Hi Everyone; I am trying to create a new variable based on the values of another variable using substr function. My original dataset looks like this: data try;
input ID status /* add $ to see second output*/ ;
datalines;
1 178
2 178
3 .
4 .
5 B55
6 B55
8 22253
9 22253
10 N65
11 N66
12 22256
;
run; I am using the following function to create the new variable. This function gives the expected results only when I input the status variable in character format ( $ ). My original dataset has status as numerical variable and I have tried too many formats and its not working. The output I get status as numeric and as character are shown below data want;
set try;
status1 = 'No';
if substr(status,1,3) in ("178","b55")
OR substr(status,1,2) in ("N6")
OR substr(status,1,4) in ("2225")
then status1='Yes';
run;
proc print data= want ;run; ObsID status status11234567891011 1 178 No 2 178 No 3 . No 4 . No 5 . No 6 . No 8 22253 No 9 22253 No 10 . No 11 . No 12 22256 No second output Obs ID status status11234567891011 1 178 Ye 2 178 Ye 3 No 4 No 5 B55 No 6 B55 No 8 22253 Ye 9 22253 Ye 10 N65 Ye 11 N66 Ye 12 22256 Ye example of formats I tried data new;
set try;
status_c =put(status, 8.);
run; any ideas
... View more