I have the following codes, may i know how to get the following remarks?
Any idea? Thanks.
data a;
input staff house car;
cards;
1234 1 0
2234 5 1
3234 2 2
;
run;
Desired result
Staff Remarks
1234 1 house and 0 car
2234 5 house and 1 car
3234 2 house and 2 car
This is fairly simple to do in SAS. But I have to ask why you want a variable with a much more complicated string containing information that you already have in your dataset? 🙂
All you need is to concatenate the given data with some literals:
data want;
set have;
remarks = catx(' ',staff,'house and',car,'car');
/* or: remarks = left(staf) || ' house and ' || left(car) || ' car'; */
run;
This is the simplest way
data a;
input staff house car;
cards;
1234 1 0
2234 5 1
3234 2 2
;
run;
data b(drop=house car);
length staff 8 remarks $17;
set a;
remarks=cat(house,' house and ',car,' car');
run;
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.