I have GHQ12 which has 13 different cohorts. I need to make it a variable with only 3 categories.
I used the following code:
data work.sampsys1; set work.sampSys; If GHQ12 = 0 then GHQ3 = 1; If GHQ12 > 0 and GHQ12 < 3 THEN GHQ3 = 2; else GHQ3 = 3; run;
I have the following error:
This is the frequency table for GHQ12:
May you please help me?
Thanks in advance,
I would rewrite the program as follows
data work.sampsys1; set work.sampSys; If GHQ12 = 0 then GHQ3 = 1; else If 0 < GHQ12 < 3 then GHQ3 = 2; else GHQ3 = 3; run;
and that should be programatically correct.
Unless the error is to do with code you haven't provided it shouldn't occur now.
I tried to add
there also seems to be a .0 in the frequency table which may need addressing
Tried to address it. Not really working. Maybe because I do not know how to address .o in my dataset!
data work.impo; set work.import; If GHQ12 = .0 then GHQ3 = 1; else If .0 < GHQ12 < 3 then GHQ3 = 2; else GHQ3 = 3; run;
I assume from the . values that this is a numeric variable? The .0 values look a bit unusual which is why I am asking.
data work.sampsys1; set work.sampSys; if GHQ12 = .0 then GHQ12 = 0; If GHQ12 = 0 then GHQ3 = 1; else If 0 < GHQ12 < 3 then GHQ3 = 2; else GHQ3 = 3; run;
That should at least tell us if the .0 is causing the problem
Hello @Sahar775 and welcome to the SAS Support Communities!
Most likely, the error messages are caused by invalid formats (e.g. w.d formats such as 1.2 or 2.2) which are permanently assigned to GHQ12 and other variables in dataset WORK.SAMPSYS. (PROC SQL might have assigned these formats.)
To see which variables are affected, run a PROC CONTENTS step like
proc contents data=work.sampsys; run;
and look at column "Format."
If all formats there are invalid (such as 2.2) or unnecessary, you can remove all formats with PROC DATASETS:
proc datasets lib=work nolist; modify sampsys; format _all_; quit;
Otherwise, you can specify individual valid formats and drop others as well by replacing format _all_; with a valid format specification in the above step. (Get back to us if you need help with this.)
Once you have changed/removed the assigned formats, check if the following step creates error messages:
data _null_; set work.sampsys(obs=0); run;
If the log is clean, you're ready to run your DATA step to create WORK.SAMPSYS1.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.