Dear Sir,
I wish to merge several files with similar variables but certain variables are defined as character in one file but as numeric in another file.
I need to standardize all these variables from character to numeric, ie Yes=1, No/others=0.
How do i do it?
Pls refer to file attached:
Eg: DualClass variable -in character- yes or no need to convert to yes=1, no=0.
other variables are BLANKCHECK CBOARD LSPMT
Pls kindly assist. Thanks a lot.
try using the code below as an example to write your own code:
data have;
input DualClass $;
cards;
yes
no
YES
No
NO
;
data have(drop=DualClass rename=(_DualClass=DualClass));
set have;
if upcase(compress(DualClass))='YES' then _DualClass=1;
if upcase(compress(DualClass))='NO' then _DualClass=0;
run;
proc print;run;
can i use input function, or should i create a dummy variable first to 1 and 0 say name it as DualClassDummy. Then i will drop the original variable DualClass and rename dualclass dummy as dual class? (so that i can do further merging with the rest of the files?)
Thanks
try using the code below as an example to write your own code:
data have;
input DualClass $;
cards;
yes
no
YES
No
NO
;
data have(drop=DualClass rename=(_DualClass=DualClass));
set have;
if upcase(compress(DualClass))='YES' then _DualClass=1;
if upcase(compress(DualClass))='NO' then _DualClass=0;
run;
proc print;run;
hi ... what do you want is a value is MISSING, another MISSING or consider it a NO (using two of your yes/no variables)
this makes MISSING = MISSING ...
data have;
input (dualclass carveout) (:$3.) ;
datalines;
yes .
no NO
YES .
. YES
NO yes
;
proc format;
invalue yn(upcase) 'YES' = 1 'NO' = 0 other = . ;
run;
data want;
set have;
_dualclass = input(dualclass,yn.);
_carveout = input(carveout,yn.);
run;
with a lot of yes/no variables, this might save some keystrokes ...
data want;
set have;
array old(*) <list all the y/n variables>;
array new(*) <list all the new variables ... same order as old>;
do _n_=1 to dim(old);
new(_n_) = input(old(_n_),yn.);
end;
run;
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.