Solved

SAS datalines having spaces

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Never store passwords in plain text or just their hash: it seems a no-brainier, but there are still plenty of people doing that. I present the why and how on this subject, offering my own real life solution that you can implement right away, bringin…
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…

821 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