BookmarkSubscribeRSS Feed
acb07010
Calcite | Level 5

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!!!

7 REPLIES 7
Tom
Super User Tom
Super User

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;

acb07010
Calcite | Level 5

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.

Patrick
Opal | Level 21

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.

pronabesh
Fluorite | Level 6

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;

pronabesh
Fluorite | Level 6

Also, did you see any error in the SAS log?

ballardw
Super User

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.

art297
Opal | Level 21

I think you will get better advice if you post the code that isn't doing what you expect.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 7 replies
  • 997 views
  • 0 likes
  • 6 in conversation