DATA Step, Macro, Functions and more

plz help

Reply
N/A
Posts: 0

plz help

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
;
Regular Contributor
Posts: 151

Re: plz help

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]
N/A
Posts: 0

Re: plz help

No missing data is there.I have to display in name column as rakesh kumar and hari without keeping Sname_is_missing.
Regular Contributor
Posts: 151

Re: plz help

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
Super User
Posts: 9,662

Re: plz help

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
Ask a Question
Discussion stats
  • 4 replies
  • 137 views
  • 0 likes
  • 3 in conversation