Hi frnds...
I have a problem that could be a simple one.
In a dataset I have two variables id and spend
like
data a;
input id spend;
cards;
1 100
1 200
1 300
2 150
2 690
;
run;
I want output like
id jan feb mar
1 100 200 300
2 150 690 .
through arrays or sql share ur simplest code ..thanks in advance
How about:
data have; input id spend; cards; 1 100 1 200 1 300 2 150 2 690 ; run; data want; set have; by id; array x{*} jan feb mar; retain jan feb mar ; if first.id then do;n=0;call missing(of x{*});end; n+1; x{n}=spend; if last.id; drop n spend; run;
Xia Keshan
How about:
data have; input id spend; cards; 1 100 1 200 1 300 2 150 2 690 ; run; data want; set have; by id; array x{*} jan feb mar; retain jan feb mar ; if first.id then do;n=0;call missing(of x{*});end; n+1; x{n}=spend; if last.id; drop n spend; run;
Xia Keshan
Same as Xia:
data have;
input id $ spend;
cards;
1 100
1 200
1 300
2 150
2 690
;
data want(drop=count spend);
set have ;
by id;
array mon(3) jan feb march;
retain mon;
if first.id then do;
call missing(of mon{*});
count=0;
end;
count+1;
mon(count)= spend;
if last.id then output;
run;
Thanks,
Naveen Srinivasan
L&T infotech
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.
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.