Solved

SAS datalines having spaces

Posted on 2010-11-09
3
1,635 Views
Last Modified: 2013-11-16
Hi, I had a quick question about the possibility of adding spaces inside a datalines data. For,example in ‘DOMESTICAB’ I would like it to really be ‘DOMESTIC AB’. How can I make this happen?

data WORK.MYSECTION;
input @1 S41_T_CODE $10.
      @12 S41_M_CODE $4.
        @17 S41_TOTAL_NUM 2.
        @20 S41_TOTAL_AMT 2.
        @23 S41_AVG_AMT 2.;
DATALINES;
DOMESTICAB MCC1 10 20 30
DOMESTICBS MCC2 20 30 40
DOMESTICAB MCC3 50 60 70
INTERNATAB MCC1 80 90 10
INTERNATBS MCC4 11 22 33
        ;
run;
0
Comment
Question by:LuckyLucks
3 Comments
 
LVL 7

Accepted Solution

by:
d507201 earned 250 total points
ID: 34097425
You can't change the input data source but you can change what goes into the SAS data set.    Create a new variable and then give it the same name as the original.


data WORK.MYSECTION;
input @1 S41_T_CODE $10.
      @12 S41_M_CODE $4.
        @17 S41_TOTAL_NUM 2.
        @20 S41_TOTAL_AMT 2.
        @23 S41_AVG_AMT 2.;

      length new_s41_t_code $11;
      new_s41_t_code=catx(' ',substr(s41_t_code,1,8),substr(s41_t_code,9));

      drop s41_t_code;
      rename new_s41_t_code=s41_t_code;

DATALINES;
DOMESTICAB MCC1 10 20 30
DOMESTICBS MCC2 20 30 40
DOMESTICAB MCC3 50 60 70
INTERNATAB MCC1 80 90 10
INTERNATBS MCC4 11 22 33
        ;
run;

data _null_;  set mysection;
      put s41_t_code;
run;
0
 
LVL 11

Assisted Solution

by:theartfuldazzler
theartfuldazzler earned 250 total points
ID: 34099434
Hi

You can change the normal delimiter of a space by setting an INFILE statement.  Below I have set my delimiter to be a pipe "|"

DATA Test;
infile datalines dlm='|' truncover;
informat x y z $20.;
INPUT x y z ;
datalines;
A B|B|C
;
RUN;
0
 

Author Comment

by:LuckyLucks
ID: 34105223
If I create the table as:
CREATE TBALE MYTABLE AS
Select T.Col1,
           T.Col2,
           T.Col3
from T;run;
quit;

And lets say the Col1 contains characters that have spaces in between, do I need to do the delimitor modification or SAS interprets that Col1 that contains spaced data is all one column?
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In today’s complex data management environments, it is not unusual for UNIX servers to be dedicated to a particular department, purpose, or database.  As a result, a SAS® data analyst often works with multiple servers, each with its own data storage…
Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now