Hi All,
I have longitudnal data and grp variable and fl variable, values of grp as 1 2 3 4 5 6... and values for fl as 1 2 3... need to create variable net.
Is there any dynamic way to get the grp and fl values
if grp=1 then do; if fl=1 then net=1; if fl=2 then net=2;end;
if grp=2 then do; if fl=1 then net=3; if fl=2 then net=4;end;
if grp=3 then do; if fl=1 then net=5; if fl=2 then net=6;end;
if grp=4 then do; if fl=1 then net=7; if fl=2 then net=8;end;
my try :
%let maxgrp=4;%let fl=2;
proc sql;
select *,
%do i=1 %to &maxgrp; j=1 %to &fl;
case when grp=&i and fl eq &j then &i*&j;
end as trt
from ids;
quit;
Thanks
Sam
Thank you Reeza!!!
can we adopt this formula under the sql? if i used in data step i got the output , but if i want to adopt for sql, getting warning on log,
"net variable already exit in XXXX dataset"
Thanks
Sam
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.