Hello,
I merged two data files from the CDC's NHIS 2012 data files ( the adult and disability files). The merge was successful however I cannot do anything with the merged data file to edit the data. I can print out the data and run freqs and means but I can not change any of the variables. For example, when I try to recode a variable or create a new variable, SAS deletes all of the variables in the data set and or says that the variable is uninitialized. If anyone can lend a hand I would greatly appreciate it.
Thanks!!!
Sounds like you are forgetting to pull in the data, like you are missing the SET statement.
data want ;
set old;
newvar = oldvar/10;
run;
thank so much for replying ....however i did use the set command to set the permanent merged file i created to a temporary file. This is what I had in my code:
LIBNAME nhisproj "P:\Project";
DATA nhisproj.NHIS2012perm;
set TMP1.NHIScombined2;
KEEP SEX RACERPI2 AFD_FLG DOINGLWA AGE_P BMI
FLA1AR MOB_2R MOB_3F
FLSOCL
AFLHCA18 AFLHCA17 UB_SS
AFLHCA13 ALHCA14A AFLHCA15; /*Subset variables*/
RUN;
PROC PRINT DATA=NHISproj.NHIS2012perm; /*Print the small subset*/
RUN;
and this works fine but then when i try to do anything with the variables like recode them or create new variables it does not work.
The KEEP statement applies to the output data set (nhisproj.NHIS2012perm). So make sure that any new variable you create is listed in the KEEP statement.
I suggest that you omit the KEEP statement while you're developing code.
You have created a permanent SAS file called NHISproj.NHIS2012perm.
Make sure when you perform data transformation you assign the correct permanent SAS path:
data NHISproj.NHIS2012perm;
set NHISproj.NHIS2012perm;
< transformation code >;
run;
Also, did you see any error in the SAS log?
I recommend that you NOT reuse the input and output data for this if you are recoding actual values of original variables as you'll end up having to redownload/combine data if you make an error.
I have seen this done to a data set reducing the number of categories such as:
if x>4 then x=4;
Else if x in (3,4) then x=2;
else if x =2 then x=0;
While modifying code affecting other variables and making changes, the value of X eventually becomes 0 or 1 when it should be 0,1,2 or 4.
Better is to
Data newrecodes;
set basedata;
<recodes>
run;
Also, Formats are often much more effecient for many grouping tasks than creating new variables.
I think you will get better advice if you post the code that isn't doing what you expect.
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.