Hi All,
I have the following data set.
ID
1
2
3
4
I want to create a new variable call New_ID and give them a corresponding Character value if ID=1-3 then New_ID='USA'; if ID=4 then New_ID='Germany'. Can someone tell me if I can do it without format function.
ID New_ID
1 USA
2 USA
3 USA
4 Germany
Thanks,able
Hi there.
Perhaps you could try this?
data in;
input ID @@;
datalines;
1 2 3 4
;
run;
data want;
set in;
attrib New_ID length=$10.;
if ID in(1:3) then New_ID='USA';
else New_ID='Germany';
run;
proc print noobs; run;
Hi there.
Perhaps you could try this?
data in;
input ID @@;
datalines;
1 2 3 4
;
run;
data want;
set in;
attrib New_ID length=$10.;
if ID in(1:3) then New_ID='USA';
else New_ID='Germany';
run;
proc print noobs; run;
Thanks Wong, It worked perfect. Can you please tell me what should I do if there are 3 category?
I want the New_ID as: value 1 to 6 = Germany, 7 to 11 = USA, 12 to 15 = Germany and missing value (.) = N/A
I wrote the following code and it's not working. Can you please help. Thanks,
data want;
set in;
attrib New_ID length=$10.;
if ID in(7:11) then New_ID='USA';
if ID in(.) then New_ID='N/A';
else New_ID='Germany';
run;
proc print noobs; run;
You are getting all "Germany" values except for .
because of
if ID in(.) then New_ID='N/A';
else New_ID='Germany';
ANY value of ID at this point other than . will yield "Germany".
You want need:
if ID in(7:11) then New_ID='USA';
else if ID in(.) then New_ID='N/A';
else New_ID='Germany';
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!
Use this tutorial as a handy guide to weigh the pros and cons of these commonly used machine learning algorithms.
Find more tutorials on the SAS Users YouTube channel.