Hey SASers!
I am trying to create a simple derive to a variable but not sure how to create it. Maybe using a when or select when statement...
I want SAS to check when a value Filled and Acting to change the pay from Leave to Present such that when variable name APtype is filled and acting for the same person id then their pay should change to present. Note the person can be in the dataset twice. See attached example:
Thank you!!
Hi,
Please try the below sql code:
proc sql;
create table want as
select id,aptype, case when count(distinct aptype)>1 then "present" else pay end as pay format=$15. from have
group by id;
quit;
thanks!! worked great! very much appreciated!
You'd better post data in this forum , not attaching a file.Nobody would like to download the file.
data have;
infile cards expandtabs truncover;
input id (aptype pay) (:$20.);
cards;
123 filled leave
123 acting present
456 filled present
789 filled leave
474 filled leave
474 acting present
212 filled suspended
287 assingment present
;
run;
data want;
merge have have(keep=id pay rename=(id=_id pay=_pay) firstobs=2);
if id=_id and pay='leave' and _pay='present' then pay='present';
drop _:;
run;
For "not working" please provide how is is not working: no output, wrong output, unexpected output. Provide example of the input, the expeceted or desired output and the actual output, and helps to be very explicit in referencing values. Also it may help to post the log of the code run in case of typos in the code or other syntax issues.
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.