Help using Base SAS procedures

convert a string into multiple field

Reply
Contributor
Posts: 45

convert a string into multiple field

I have a raw dat like

ram "history,math geography"
hari "physics,, math chemistry"

I want to create a data set like

history math geography
physics math chemistry Message was edited by: arpit
PROC Star
Posts: 7,473

Re: convert a string into multiple field

Would something like the following suffice?:

data want (drop=i classes);
informat classes $30.;
array class(3) $10.;
input name $ classes &;
classes=compress(classes,'"');
do i=1 to 3;
class(i)=scan(classes,i);
end;
cards;
ram "history,math geography"
hari "physics,, math chemistry"
;
run;

HTH,
Art
---------
> I have a raw dat like
>
> ram "history,math geography"
> ari "physics,, math chemistry"
>
> I want to create a data set like
>
> history math geography
> physics math chemistry
>
> Message was edited by: arpit
Super User
Posts: 10,028

Re: convert a string into multiple field

How about this:
[pre]
data want(drop=row);
infile "c:\rawdata.txt" length=len;
input row $varying200. len;
want_row=compbl(translate(scan(row,2,'"'),' ',','));
run;
[/pre]

Ksharp
Regular Contributor
Posts: 229

Re: convert a string into multiple field

data l;
input name $ classes $40.;
classes=compress(classes,'"');
c1=scan(classes,1);
c2=scan(classes,2);
c3=scan(classes,3);
cards;
ram "history,math geography"
hari "physics,, math chemistry"
run;
Ask a Question
Discussion stats
  • 3 replies
  • 99 views
  • 0 likes
  • 4 in conversation