BookmarkSubscribeRSS Feed
deleted_user
Not applicable
how to get the output of this program. I am unable to get output.

data abc;
input pid name $ age race $;
cardsl
101 rakesh kumar 34 asian
102 hari 29 african
;
4 REPLIES 4
Oleg_L
Obsidian | Level 7
I'm also having a difficulties with your sample data.
The variable name in the first row consists of two parts, but in the second row the second part is missing.
Don't you miss something? Does your actual data as inconsistent as you post it?

[pre]
data abc;
infile cards missover;
input pid fname :$30. sname :$30. age race :$10.;
cards;
101 rakesh kumar 34 asian
102 hari Sname_is_missing 29 african
;
[/pre]
deleted_user
Not applicable
No missing data is there.I have to display in name column as rakesh kumar and hari without keeping Sname_is_missing.
Oleg_L
Obsidian | Level 7
The code below is a solution from this forum poster "Data _null_".

http://support.sas.com/forums/thread.jspa?messageID=51217접

>
http://support.sas.com/forums/thread.jspa?messageID=51217접



[pre]

data a;
retain dlm ' ';
infile cards truncover dsd dlm=dlm;
input @;
end = length(_infile_)+1;
do j = 1 to 2;
end = find(_infile_,dlm,-(end-1));
end;
start = find(_infile_,dlm,1);
length = end-start-1;
input pid :8. name $varying50. length +1 age :8. race :$10.;
keep pid name age race;
cards;
101 rakesh kumar 34 asian
102 hari 29 african
;



[/pre]

Message was edited by: Oleg_L

Message was edited by: Oleg_L Message was edited by: Oleg_L
Ksharp
Super User
It is interesting.Ok, Let's overcome it.


[pre]
data temp;
infile datalines truncover;
input pid remain $100.;
name=substr(remain,1,anydigit(remain)-1);
age=scan(remain,-2);
race=scan(remain,-1);
drop remain;
datalines;
101 rakesh kumar 34 asian
102 hari 29 african
;
run;
[/pre]


Ksharp

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1142 views
  • 0 likes
  • 3 in conversation