Solved

SAS datalines having spaces

Posted on 2010-11-09
3
1,542 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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

I guess that all of us know that caching the data usually increase the performance, but I worried if all of us are aware about the risk that caching the data provides and how to minimize this.  That’s the reason why I decided to write this short art…
APEX (Application Express) is used to develop a web application from Oracle. SQL Workshop is one of the tools that comes with Oracle APEX to query or modify the database objects or to make any changes to the structure.
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…

706 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

19 Experts available now in Live!

Get 1:1 Help Now