DATA Step, Macro, Functions and more

Can some one please help me with editing a data file?

Reply
New Contributor
Posts: 2

Can some one please help me with editing a data file?

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

Super User
Super User
Posts: 6,502

Re: Can some one please help me with editing a data file?

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;

New Contributor
Posts: 2

Re: Can some one please help me with editing a data file?

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.

Respected Advisor
Posts: 3,900

Re: Can some one please help me with editing a data file?

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.

Contributor
Posts: 58

Re: Can some one please help me with editing a data file?

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;

Contributor
Posts: 58

Re: Can some one please help me with editing a data file?

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

Super User
Posts: 10,538

Re: Can some one please help me with editing a data file?

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.

PROC Star
Posts: 7,364

Re: Can some one please help me with editing a data file?

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

Ask a Question
Discussion stats
  • 7 replies
  • 352 views
  • 0 likes
  • 6 in conversation