BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Sathish_jammy
Lapis Lazuli | Level 10

 

 

data example2;
infile cards delimiter = ' ' dsd;
length Name $30;
input Name$ ID Score;
cards;
Deepanshu Bhalla 22 987
AttaPat 217 564
Xonxiangnam Samnuelnarayan 33 544
;
proc print noobs;
run;

 

 

SAS Output

Name ID Score
Deepanshu Bhalla 22 987..

 

Even if i use 

length Name :$30; (the same partial O/P occur)

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26

You can't directly.  What you have here is bad data.  The reason it is bad is because the variables contain the "delimiter", which means there is no logical way to identify where a variable starts and where it finishes, hence it is bad data.  

This illustrates good data, where the delimiter is distinct:

data example2;
  infile cards delimiter=',' dsd;
  length Name $30;
  input Name$ ID Score;
cards;
Deepanshu Bhalla,22,987
AttaPat,217,564
Xonxiangnam Samnuelnarayan,33,544
;
run;

Personally I would send the data back with a fail note, and how to correct it.  Otherwise you will need to read in the data as text, then write some text parse statements to split it up as you want. 

 

View solution in original post

3 REPLIES 3
RW9
Diamond | Level 26 RW9
Diamond | Level 26

You can't directly.  What you have here is bad data.  The reason it is bad is because the variables contain the "delimiter", which means there is no logical way to identify where a variable starts and where it finishes, hence it is bad data.  

This illustrates good data, where the delimiter is distinct:

data example2;
  infile cards delimiter=',' dsd;
  length Name $30;
  input Name$ ID Score;
cards;
Deepanshu Bhalla,22,987
AttaPat,217,564
Xonxiangnam Samnuelnarayan,33,544
;
run;

Personally I would send the data back with a fail note, and how to correct it.  Otherwise you will need to read in the data as text, then write some text parse statements to split it up as you want. 

 

novinosrin
Tourmaline | Level 20

@Sathish_jammy  you can certainly make SAS read your data as is without touching your values but of course data is a bad data regardless. 

novinosrin
Tourmaline | Level 20
data example2;
infile cards delimiter = ' ' ;
input @;
length Name $30;
Name=substr(_infile_,1, anydigit(_infile_)-1);
input @(anydigit(_infile_)) ID score;
cards;
Deepanshu Bhalla 22 987
AttaPat 217 564
Xonxiangnam Samnuelnarayan 33 544
;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 753 views
  • 2 likes
  • 3 in conversation