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';
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.