DATA Step, Macro, Functions and more

SAS Unexpected Behavior

Reply
Highlighted
Contributor
Posts: 34

SAS Unexpected Behavior

Hello all,

 

I use SAS 9.4 and having some issues. I will try to explain what I am facing.

 

I am working on a project where I created some temporary datasets for example temp1-temp6. In each temp files I created some new variables. When I am doing a proc print of temp1, its giving me variables that I created in temp5 along with the variables that I have in temp1.

 

This is happening in 2 of the SAS programs I worked on today.

 

I opened a ticket at SAS Technical support but just wondering if any of the smart brains here can help me.

 

Thanks

SAS Super FREQ
Posts: 305

Re: SAS Unexpected Behavior

Since you did not supply your code, I can't say what is going on.  That said, after 38 years experience with SAS, I can say with certainty, even without seeing your code that when you print temp1, you are seeing the variables that you put in temp1.  You are only seeing variables from temp5 if you also put them in temp1.  This is a user error not a SAS error.

Super User
Posts: 19,860

Re: SAS Unexpected Behavior

Are you using PROC PRINT without the DATA=?

Super User
Posts: 11,343

Re: SAS Unexpected Behavior

When you have a question about code behavior show the code.

You may need to provide brief example data that duplicates the behavior. If so data steps that will generate the working data are the best way to get complete answers.

 

My first guess would be misspelled dataset names somewhere.

Second would be not quite careful use of
Data temp1;

   set temp1;  /*OR accidental use of temp5*/

...

run;

 

Third would explicit or implicit use of the _last_ dataset.

 

Data work.junk;

   set;

run;

 

will copy the last written dataset into work.junk.

Contributor
Posts: 34

Re: SAS Unexpected Behavior

Hello all, Below are my codes

 

data temp1;

merge a.icustay_FY17  a.nutrition_FY17  a.GI_FY17  a.NPO_FY17;

by encounter date;

run;

 

proc print data=work.temp1;

run;

proc sort data=work.temp1;

by encounter icu_stay;

run;

 

proc summary data=work.temp1;

var ts;

by encounter icu_stay;

output out=temp2(keep=encounter icu_stay first last)min=first max=last;

run;

 

 

 data work.temp3;

 

 merge work.temp1 work.temp2;

by encounter icu_stay;

rename first=admit_ts2;

rename last=discharge_ts2;

ts_24hr2=first+(60*60*24);

format ts_24hr2 datetime16.;

run;

 

Issue is when I am running a proc print of temp1, it is showing me the variables coming from the file I am merging plus variables created in temp3 (for example admit_ts2, discharge_ts2,ts_24hr2,n_day). I haven't seen this thing in my 2 years of experience. I spoke to one of my colleague who is also a SAS programmer, more experienced than me. He said that he cannot see anything wrong in my codes and there is no error in log. He also didn't know that what is causing this unexpected behavior. He gave me a suggestion to move my files from shared folder to a personal folder and run the program. I am going to do this and see if it works.

  

Please let me know if you can see any error or you have any suggestions.

Thanks to all of you for replying

SAS Super FREQ
Posts: 305

Re: SAS Unexpected Behavior

Run proc contents on all of the input data sets before the merge.  Run proc contents on the data set after the merge.  You will only see the variables from the input data sets in the output data set.  

SAS Super FREQ
Posts: 305

Re: SAS Unexpected Behavior

Posted in reply to WarrenKuhfeld

If you do something like this, but without the semicolon on the DATA statement, you could replace TEMP1 and get results that you did not expect if you subsequently print temp1.  Perhaps that is what you did?

data work.temp3;
   merge work.temp1 work.temp2;

 

Ask a Question
Discussion stats
  • 6 replies
  • 102 views
  • 3 likes
  • 4 in conversation