BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
michelconn
Quartz | Level 8

Hello all, I am running a macro that relies on various %goto statments. My issues is that some of them are being ignored and I can't figure out why. Here is the statement with issues. 

 

*ASKS SAS IF CV TYPE OR GD TYPE SHOULD BE SELECTED NEXT CHECKING WHICH HAS THE FIRST OCCURING BLANK;
%if %sysevalf(%superq(VAR1)=,boolean) and %sysevalf(%superq(VAR2) ne ,boolean) %then %goto cvstart;
%if %sysevalf(%superq(VAR1) ne ,boolean) and %sysevalf(%superq(VAR2)=,boolean) %then %goto gdstart;

*GOES TO SPECIFIC POSITION IN MACRO DEPENDING ON PREVIOUS CVTYPE;
%cvstart: %put Curve Iteration &i;
%if "&VAR4"="T" %then %goto tstart;
%if "&VAR4"="C" %then %goto cstart;
%if "&VAR4"="CC" %then %goto ccstart;
%if "&VAR4"="RC" %then %goto rcstart;
%put ERROR IN CURVE;
%goto continue;

*GOES TO SPECIFIC POSITION IN MACRO DEPENDING ON PREVIOUS GDTYPE;
%gdstart: %put Grade Iteration &i;
%if "&VAR7"="S" %then %goto sstart;
%if "&VAR7"="Crest1" %then %goto crest1start;
%if "&VAR7"="Crest2" %then %goto crest2start;
%if "&VAR7"="Sag1" %then %goto sag1start;
%if "&VAR7"="Sag2" %then %goto sag2start;
%put ERROR IN GRADE;
%goto continue;

The goto statement that isn't working is sstart. What should be happening is the macro goes to sstart runs those procedures and go to the next loop. Instead it is skipping the goto statement  printing the error and going to the end of the loop with the continue statement.

 

Below are the macro variables created by the macro on this particular iteration. I use put statements to know this.

VAR1=T
VAR2=
VAR3=2: Rolling
VAR4=T
VAR5=S
VAR6= 13
VAR7=S
VAR8= 1.5
Grade Iteration 13
ERROR IN GRADE

 

I can't figure out why SAS doesn't think "&VAR7"="S". The macro variables are being created by sequentially scanning a line of a dataset each iteration. I even went to dataset the macro variables are being created from and copied and pasted the "S" value into the code. 

 

Thanks 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

Went back to the DATA set?  That makes me suspect you are using CALL SYMPUT to create these macro variables.  If that's the case, the likely error is that &VAR7 contains trailing blanks.  You could always verify that by changing the %PUT statement to:

 

%put *&VAR7*;

 

In macro language, "S" is not equal to "S   " so the match is not being found.  The simplest solution would be to switch from CALL SYMPUT to CALL SYMPUTX in the DATA step.  That would remove any leading and trailing blanks when creating macro variables.

View solution in original post

3 REPLIES 3
Astounding
PROC Star

Went back to the DATA set?  That makes me suspect you are using CALL SYMPUT to create these macro variables.  If that's the case, the likely error is that &VAR7 contains trailing blanks.  You could always verify that by changing the %PUT statement to:

 

%put *&VAR7*;

 

In macro language, "S" is not equal to "S   " so the match is not being found.  The simplest solution would be to switch from CALL SYMPUT to CALL SYMPUTX in the DATA step.  That would remove any leading and trailing blanks when creating macro variables.

michelconn
Quartz | Level 8

You are correct this is the code I am using 

DATA _NULL_;
	IF 0 THEN SET &SCANFILE NOBS=X;
	CALL SYMPUT('RECCOUNT',X);
STOP;
RUN;
%DO I=1 %TO &RECCOUNT;
DATA _NULL_;
SET &SCANFILE (FIRSTOBS=&I);
	CALL SYMPUT('VAR1',&FIELD1);
	CALL SYMPUT('VAR2',&FIELD2);
	CALL SYMPUT('VAR3',&FIELD3);
	CALL SYMPUT('VAR4',&FIELD4);
	CALL SYMPUT('VAR5',&FIELD5);
	CALL SYMPUT('VAR6',&FIELD6);
	CALL SYMPUT('VAR7',&FIELD7);
	CALL SYMPUT('VAR8',&FIELD8);
STOP;
RUN;

 

I went back and added the *'s and it looks like you are right the macro is putting in some trailing blanks. I'll switch to symputx and see what happens. 

 

VAR1=*T *
VAR2=*S *
VAR3=*2: Rolling *
VAR4=*T *
VAR5=*S *
VAR6=* 2*
VAR7=*S *
VAR8=* 1.5*
Skipped interation 2

ballardw
Super User

You have left out a lot of needed information.

 

You should show the entire macro as the issue could well be elsewhere in your code such as another comparison such as the VAR4 stuff skipping past the evaluation for Var7. With unconditional %goto continue that what ever happens there is a likely place to investigate.

 

So many GOTO statements is what is sometimes referred to as "spaghetti code" because things get so intertwined it can be very difficult to trace out just what happens.

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
  • 3 replies
  • 1992 views
  • 1 like
  • 3 in conversation