I am trying to categorized data based on what the last two characters are in a variable
rand1=rand('uniform');
rand2=rand('uniform');
if rand1>0.90 Then do;
if (POIDS>0 and substr(USAGE,2,2) IN('20','21')) then do;
if rand2>0.5 then RadiusSurcharge="A";
ELSE RadiusSurcharge="B";
end;
if (POIDS=0 and substr(USAGE,2,2) IN('20','21')) then do;
if rand2>0.5 then RadiusSurcharge="C";
else RadiusSurcharge="D";
end;
end;
if rand1>0.90 then do;
if (POIDS>0 and substr(USAGE,2,2) NE('20','21')) then do;
if rand2>0.5 then RadiusSurcharge="E";
else RadiusSurcharge="F";
end;
if (POIDS=0 and substr(USAGE,2,2) NE('20','21')) then do;
if rand2<0.333 then RadiusSurcharge="G";
else if rand2>0.333 and rand2<0.666 then do RadiusSurcharge="H";
else RadiusSurcharge="I";
end;
end;
end;
The top half, I use IN function so that the obs that does contain '20' or '21' gets assigned other variables accordinly
For the second half I am trying to use NE so that the observations that don't contain '20' or '21' but i keep getting the following errors,
if (POIDS>0 and substr(USAGE,2,2) NE('20','21')) then do;
_
388
200
ERROR 388-185: Expecting an arithmetic operator.
ERROR 200-322: The symbol is not recognized and will be ignored.
Please advise!
Correction
if (POIDS>0 and substr(USAGE,2,2) NOT IN ('20','21')) then do;
Notes:
1. To filter a list that has more than one operand to evaluate, an equality operator is not appropriate . For an equality operator to work, you would have to work with just one operand
2. While you coded your IN the list correctly, all you need is NOT IN for all values that are not 20,21 to be true
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.