BookmarkSubscribeRSS Feed
AMFR
Quartz | Level 8

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

6 REPLIES 6
WarrenKuhfeld
Rhodochrosite | Level 12

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.

Reeza
Super User

Are you using PROC PRINT without the DATA=?

ballardw
Super User

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.

AMFR
Quartz | Level 8

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

WarrenKuhfeld
Rhodochrosite | Level 12

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.  

WarrenKuhfeld
Rhodochrosite | Level 12

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;

 

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
  • 6 replies
  • 803 views
  • 3 likes
  • 4 in conversation