DATA Step, Macro, Functions and more

Please help me to get the VARIABLE OF VARYING LENGTH

Accepted Solution Solved
Reply
Highlighted
New Contributor
Posts: 2
Accepted Solution

Please help me to get the VARIABLE OF VARYING LENGTH

[ Edited ]

 

 

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)

 

 


Accepted Solutions
Solution
Wednesday
Super User
Super User
Posts: 9,402

Re: Please help me to get the VARIABLE OF VARYING LENGTH

Posted in reply to Sathish_jammy

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


All Replies
Solution
Wednesday
Super User
Super User
Posts: 9,402

Re: Please help me to get the VARIABLE OF VARYING LENGTH

Posted in reply to Sathish_jammy

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. 

 

PROC Star
Posts: 1,569

Re: Please help me to get the VARIABLE OF VARYING LENGTH

Posted in reply to Sathish_jammy

@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. 

PROC Star
Posts: 1,569

Re: Please help me to get the VARIABLE OF VARYING LENGTH

Posted in reply to Sathish_jammy
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
;
☑ This topic is solved.

Need further help from the community? Please ask a new question.

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