BookmarkSubscribeRSS Feed
Krysia24
Obsidian | Level 7

In case this is important, I am using SAS EG 5.1.  

 

I am working with a code, and in it, I code a lot of variables and then do some analytics like proc surveymeans and proc surveyreg. 

Important to note, when I run this code the first time - it works without any issues. Now, whenever I re-run the code, despite not making any changes to the original code, some of the variables suddenly now change so that the observations for that variable are all coded to missing. So for, example, if I had a variable "color" - all of its observations are now "." in the dataset. So now when I attempt to run some analytics, I can't run analytics on those variables. 

 

Is this some sort of internal issue? Because it's clearly not my code if it runs the first time but not repeatedly. 

 

 

6 REPLIES 6
Reeza
Super User

Any messages in your log, notes or errors?

Do you have any recursive references, ie 

 

data want;

set want; 

 

or conditional execution of code that checks for the existence of tables? 

 

Without seeing the code it's hard to say. It's possible it's an EG glitch, but 99% of the time it's a logic error in the code - not a syntax error why your log may be clean. 

Krysia24
Obsidian | Level 7

Hi Reeza, 

 

Unfortunately, it's a very long code. There are no warnings or errors in the log when this happens. And what's weird is that it runs fine if you run it once. But if you run it again, suddenly some of the variables all have missing observations. So then I have to close out the program, re-open it, and run it all again... which is really eating a lot of time. 

 

If it's still more helpful to send my code, I can do that. It's just a lot to sort through! 

Krysia24
Obsidian | Level 7

Actually here is a small example of something that's no longer working when I re-run it. In this example, the variable "employed" at first was coded correctly and the surveyfreq procedure ran correctly. Then when I re-ran this piece of code, all the observations for "employed" suddenly changed to "." so the surveyfreq procedure no longer was useful. 

____

 

/*separating out employment variable Q60 into separate variables for each type of employment*/
DATA work.abcdata;
SET work.abchmvdata;
IF Q60_clean = 1 THEN employed = 1;
ELSE IF Q60_clean IN (2:7) THEN employed = 0;
ELSE employed = . ;
IF Q60_clean = 2 THEN outofwork1yrplus = 1;
ELSE IF Q60_clean IN (1,3:7) THEN outofwork1yrplus = 0;
ELSE outofwork1yrplus = . ;
IF Q60_clean = 3 THEN outofwork1yrless = 1;
ELSE IF Q60_clean IN (1:2, 4:7) THEN outofwork1yrless = 0;
ELSE outofwork1yrless = . ;
IF Q60_clean = 4 THEN homemaker = 1;
ELSE IF Q60_clean IN (1:3, 5:7) THEN homemaker = 0;
ELSE homemaker = . ;
IF Q60_clean = 5 THEN student = 1;
ELSE IF Q60_clean IN (1:4, 6:7) THEN student = 0;
ELSE student = .;
IF Q60_clean = 6 THEN retired = 1;
ELSE IF Q60_clean IN (1:5, 7) THEN retired = 0 ;
ELSE retired = . ;
IF Q60_clean = 7 THEN unabletowork = 1;
ELSE IF Q60_clean IN (1:6) THEN unabletowork = 0;
ELSE unabletowork = . ;
RUN;

 

 

PROC SURVEYFREQ data=work.abcdata;
STRATA weightstrata;
TABLES Q60_Clean employed;
weight baseweight;
RUN;

Reeza
Super User

Run it step by step to figure out where it breaks. If you know it's employed variable, see if any code between shown step and final are changing the variable again. 

ballardw
Super User

"When rerunning" makes me believe there is lots of code you are repeating.

Something else to look for: Changing order of steps when "rerunning". It may be that for some reason your work.abchmvdata no longer has the expected values of the q60_clean variable.

 

 

 

Rick_SAS
SAS Super FREQ

When this happens for me, it is usually because the code expects that certain data sets (or variables) are not created before the code runs. As Reeza suggests, look for DATA A; SET A. You can test if that is the case by using PROC DATASETS at the beginning of your program to delete any data sets in WORK.  

 

For other tips, see Rosenbloom and Lafler (2012), "Best Practices: Clean House to Avoid Hangovers."

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
  • 1722 views
  • 0 likes
  • 4 in conversation