Solved

SAS datalines having spaces

Posted on 2010-11-09
3
2,094 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

A company’s centralized system that manages user data, security, and distributed resources is often a focus of criminal attention. Active Directory (AD) is no exception. In truth, it’s even more likely to be targeted due to the number of companies …
A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
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…

738 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