BookmarkSubscribeRSS Feed
Geeman
Fluorite | Level 6

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!!

5 REPLIES 5
stat_sas
Ammonite | Level 13

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;

Geeman
Fluorite | Level 6

thanks!! worked great! very much appreciated!

Ksharp
Super User

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;
Geeman
Fluorite | Level 6
Thanks for this Ksharp. Still not working. Merge and Rename working correctly.
ballardw
Super User

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.

sas-innovate-2024.png

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.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 1263 views
  • 0 likes
  • 4 in conversation