The following worked for me:
libname thedata '/folders/myfolders'; DATA EXMED_NOTMULTI_3; set thedata.exmed_test1 (rename=(distancetestmarche6minfinprogram=_d)); distancetestmarche6minfinprogram=input(compress(_d,'kd'),12.); run; proc freq data=EXMED_NOTMULTI_3 ; tables distancetestmarche6minfinprogram; where not missing(distancetestmarche6minfinprogram); run;
Art, CEO, AnalystFinder.com
Hello,
Thanks for the reply,
I tried it but it did not work (problem with INPUT) . I find it weird. here is the log.
407 DATA EXMED_test2;
408 set exmed_test1 (rename=(distancetestmarche6minfinprogram=_d));
409 distancetestmarche6minfinprogram=input(compress(_d,'kd'),12.);
410 run;
NOTE: Invalid argument to function INPUT at ligne 409 colonne 36.
_d=Inc Fumeacutellementadmission=Dans passe ID=2 distancetestmarche6minfinprogram=. _ERROR_=1
_N_=2
NOTE: Invalid argument to function INPUT at ligne 409 colonne 36.
_d=n/a Fumeacutellementadmission=Jamais ID=16 distancetestmarche6minfinprogram=. _ERROR_=1
_N_=16
NOTE: Invalid argument to function INPUT at ligne 409 colonne 36.
_d=Inc Fumeacutellementadmission=Dans passe ID=85 distancetestmarche6minfinprogram=. _ERROR_=1
_N_=85
NOTE: Invalid argument to function INPUT at ligne 409 colonne 36.
_d=Inc Fumeacutellementadmission=Dans passe ID=92 distancetestmarche6minfinprogram=. _ERROR_=1
_N_=92
NOTE: Invalid argument to function INPUT at ligne 409 colonne 36.
_d=Inc Fumeacutellementadmission=Jamais ID=116 distancetestmarche6minfinprogram=. _ERROR_=1
_N_=116
NOTE: Invalid argument to function INPUT at ligne 409 colonne 36.
_d=Inc Fumeacutellementadmission=Jamais ID=133 distancetestmarche6minfinprogram=. _ERROR_=1
_N_=133
NOTE: Invalid argument to function INPUT at ligne 409 colonne 36.
_d=Inc Fumeacutellementadmission=Dans passe ID=141 distancetestmarche6minfinprogram=. _ERROR_=1
_N_=141
NOTE: Invalid argument to function INPUT at ligne 409 colonne 36.
_d=Inc Fumeacutellementadmission=Jamais ID=155 distancetestmarche6minfinprogram=. _ERROR_=1
_N_=155
NOTE: Invalid argument to function INPUT at ligne 409 colonne 36.
_d=Inc Fumeacutellementadmission=Jamais ID=159 distancetestmarche6minfinprogram=. _ERROR_=1
_N_=159
NOTE: Invalid argument to function INPUT at ligne 409 colonne 36.
_d=Inc Fumeacutellementadmission=Presentemen ID=161 distancetestmarche6minfinprogram=. _ERROR_=1
_N_=161
NOTE: Invalid argument to function INPUT at ligne 409 colonne 36.
_d=Inc Fumeacutellementadmission=Jamais ID=163 distancetestmarche6minfinprogram=. _ERROR_=1
_N_=163
NOTE: Invalid argument to function INPUT at ligne 409 colonne 36.
_d=Inc Fumeacutellementadmission=Presentemen ID=165 distancetestmarche6minfinprogram=. _ERROR_=1
_N_=165
NOTE: Invalid argument to function INPUT at ligne 409 colonne 36.
_d=Unk Fumeacutellementadmission=Dans passe ID=172 distancetestmarche6minfinprogram=. _ERROR_=1
_N_=172
NOTE: Invalid argument to function INPUT at ligne 409 colonne 36.
_d=Inc Fumeacutellementadmission=Dans passe ID=180 distancetestmarche6minfinprogram=. _ERROR_=1
_N_=180
NOTE: Invalid argument to function INPUT at ligne 409 colonne 36.
_d=Inc Fumeacutellementadmission=Jamais ID=189 distancetestmarche6minfinprogram=. _ERROR_=1
_N_=189
NOTE: Invalid argument to function INPUT at ligne 409 colonne 36.
_d=Inc Fumeacutellementadmission=Dans passe ID=190 distancetestmarche6minfinprogram=. _ERROR_=1
_N_=190
NOTE: Invalid argument to function INPUT at ligne 409 colonne 36.
_d=Inc Fumeacutellementadmission=Dans passe ID=193 distancetestmarche6minfinprogram=. _ERROR_=1
_N_=193
NOTE: Invalid argument to function INPUT at ligne 409 colonne 36.
_d=Inc Fumeacutellementadmission=Presentemen ID=194 distancetestmarche6minfinprogram=. _ERROR_=1
_N_=194
NOTE: Invalid argument to function INPUT at ligne 409 colonne 36.
_d=n/a Fumeacutellementadmission=Jamais ID=196 distancetestmarche6minfinprogram=. _ERROR_=1
_N_=196
NOTE: Invalid argument to function INPUT at ligne 409 colonne 36.
WARNING: Limit set by ERRORS= option reached. Further errors of this type will not be printed.
_d=Inc Fumeacutellementadmission=Jamais ID=205 distancetestmarche6minfinprogram=. _ERROR_=1
_N_=205
NOTE: Mathematical operations could not be performed at the following places. The results of
the operations have been set to missing values.
Each place is given by: (Number of times) at (Line):(Column).
54 dans 409:36
NOTE: There were 410 observations read from the data set WORK.EXMED_TEST1.
NOTE: The data set WORK.EXMED_TEST2 has 410 observations and 4 variables.
NOTE: DATA statement used (Total process time):
real time 0.02 seconds
cpu time 0.03 seconds
Actually, it did work, but the log showed all of the records where alpha characters were shown. You can do it suppressing those errors with the following:
libname thedata '/folders/myfolders'; DATA EXMED_NOTMULTI_3; set thedata.exmed_test1 (rename=(distancetestmarche6minfinprogram=_d)); distancetestmarche6minfinprogram=input(compress(_d,'kd'),?? 12.); run; proc freq data=EXMED_NOTMULTI_3 ; tables distancetestmarche6minfinprogram; where not missing(distancetestmarche6minfinprogram); run;
Art, CEO, AnalystFinder.com
Thanks again,
I'm done with one variable, one more to go,
the other variable has character values that I want to convert to categories, it should be straight forward:
Here is what I tried,
IF Fumeacutellementadmission = 'Jamais' THEN SMOKING = 0 ;
IF Fumeacutellementadmission = 'Dans passe' THEN SMOKING = 1 ;
IF Fumeacutellementadmission = 'Presentemen' THEN SMOKING = 2 ;
IF Fumeacutellementadmission = 'Chaque jour' THEN SMOKING = 2 ;
IF Fumeacutellementadmission = 'Inconnu' THEN SMOKING = . ;
IF Fumeacutellementadmission = . THEN SMOKING = . ;
Thanks
Your code works for the second variable. Given the small size of your dataset, no reason to change it. For larger datasets, I'd simplify it by either using a select statement or preceding the 2nd thru last if statements with an else statement.
However, probably more work to change the code then necessary (given your small dataset), but a good practice to get into for the future.
Art, CEO, AnalystFinder.com
Then, if you're problem is now solved, mark the post that provided the solution so that others won't waste time trying to solve an already solved problem.
Art, CEO, AnalystFinder.com
Also , what about the other variable, this one has character values that I want to convert to categories, it should be straight forward:
Here is what I tried,
IF Fumeacutellementadmission = 'Jamais' THEN SMOKING = 0 ;
IF Fumeacutellementadmission = 'Dans passe' THEN SMOKING = 1 ;
IF Fumeacutellementadmission = 'Presentemen' THEN SMOKING = 2 ;
IF Fumeacutellementadmission = 'Chaque jour' THEN SMOKING = 2 ;
IF Fumeacutellementadmission = 'Inconnu' THEN SMOKING = . ;
IF Fumeacutellementadmission = . THEN SMOKING = . ;
Thanks
Your last IF statement you are trying to compare your character variable to a numeric missing value. This will cause SAS to try to convert your character variable to a number. For example run this program to see the same effect.
data _null_;
x='ABC';
if x=. then put 'missing';
run;
So any value that did not look like a number will evaluate as being equal to numeric missing value. The reason why adding the ELSE keyword made it work is because then you only try to execute the invalid syntax when the value does match one of the expected results.
If you want to test if a character variable is missing either compare it to a string that only has spaces.
if x=' ' then put 'missing';
Or use the MISSING() function.
if missing(x) then put 'missing';
If you want to compare it to an actual period then use quotes to make the period into a string literal and not a numeric missing value.
if x='.' then put 'missing';
So your code should look more like:
IF Fumeacutellementadmission = 'Jamais' THEN SMOKING = 0 ;
else IF Fumeacutellementadmission = 'Dans passe' THEN SMOKING = 1 ;
else IF Fumeacutellementadmission = 'Presentemen' THEN SMOKING = 2 ;
else IF Fumeacutellementadmission = 'Chaque jour' THEN SMOKING = 2 ;
else IF Fumeacutellementadmission = 'Inconnu' THEN SMOKING = . ;
else IF Fumeacutellementadmission = ' ' THEN SMOKING = . ;
else put 'Unknown value' Fumeacutellementadmission = $quote.;
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!
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.