Hi,
I created a format file that names the levels of categorical variables "workcode". The format value code is $workload.
Following is my code:
data df;
set df1;
format workcode $workload30. ;
if workcode = "Other" then delete ;
run;
Basically, I want to delete all other variables assigned by the format statement as "Other" in the separate format file. However, the datastep doesn't seem to recognize the condition statement right after format. No delete action was performed. Does anyone know what caused the issue?
Thanks!
Or
if put(workcode,$workload30.) = "Other" then delete
Variables always maintain their value and that is used for comparisons. For formatted values you have to explicitly create the formatted value. Note that you may create a value that still doesn't compare as expected if the format includes leading spaces.
Since We do not have a sample of your data, I am assuming this may help
data df;
set df1;
new_workcode=put(workcode,$workload30.);
*format workcode $workload30. ;
if new_workcode= "Other" then delete ;
run;
Or
if put(workcode,$workload30.) = "Other" then delete
Variables always maintain their value and that is used for comparisons. For formatted values you have to explicitly create the formatted value. Note that you may create a value that still doesn't compare as expected if the format includes leading spaces.
Thank you! That is ingenious!
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.