BookmarkSubscribeRSS Feed
khill2
Calcite | Level 5

Hello, I have inherited a legacy SAS program with a Proc Report at the end that works fine in Base SAS 9.4 but aborts in Enterprise Guide 7.15. The program uses macro variables to dynamically generate what will be column headers by the time the program gets to the Proc Report. These column headers translate to numerals. I am new to Proc Report and I don't understand what the underscore-ampersand is doing. I would really prefer to be working in Enterprise Guide so would appreciate any ideas to adjust the Proc Report to work there. 

 

options symbolgen;
options missing=.;

%let year=20229;	/*Most Recent Fall semester*/

%macro vars ;
%global ym1 ym2 ym3 ym4 yyyy yyyym1 yyyym2 yyyym3 yyyym4 ;
%let ym1=%eval(&year-10); 
%let ym2=%eval(&year-20);
%let ym3=%eval(&year-30);		
%let ym4=%eval(&year-40);

%let yyyy=%substr(&year,1,4);
%let yyyym1=%substr(&ym1,1,4);
%let yyyym2=%substr(&ym2,1,4);
%let yyyym3=%substr(&ym3,1,4);
%let yyyym4=%substr(&ym4,1,4);
%mend vars;
%vars ;

data have;
length year $ 5 total 8. ftfac 8. ptfac 8.;
infile cards dlm= '#' ;                                                                                                                 
input year $ total ftfac ptfac;                                                                                                         
cards ;
20189#500#250#250
20199#550#300#250
20209#600#300#300
20219#650#350#300
20229#700#350#350
 ;                                                                                                                                       
run ;  

proc sort data=have ;  by year; run ;

proc transpose data=have out=have2 (rename=(_name_=description)); id year; run ;

proc report data=have2 nowd;
	column description _&ym4 _&ym3 _&ym2 _&ym1 _&year;
	define description /'';
	define _&ym4 /display "Fall &yyyym4";
	define _&ym3 /display "Fall &yyyym3";
	define _&ym2 /display "Fall &yyyym2";
	define _&ym1 /display "Fall &yyyym1";
	define _&year /display "Fall &yyyy";
run;

When this is run in EG, I get the errors:

ERROR: Variable _20189 is not on file WORK.HAVE2.
ERROR: Variable _20199 is not on file WORK.HAVE2.
ERROR: Variable _20209 is not on file WORK.HAVE2.
ERROR: Variable _20219 is not on file WORK.HAVE2.
ERROR: Variable _20229 is not on file WORK.HAVE2.

 

Thank you very much!

 

3 REPLIES 3
totoleheros
SAS Employee

@khill2 

sorry to pick this 2 months after you reported it. Do not know if an answer is still needed.

I tested your code in 9.4 ("classic SAS"), and I get the same error 

Options validvarname should be set to V7 before running proc transpose to create variables starting with an underscore

options validvarname=V7;
khill2
Calcite | Level 5
Thanks, but I ended up renaming the variables to valid SAS varnames before
running the proc transpose. I was more curious to find some
documentation/info regarding the underscore 'trick' that works in Base SAS
but not SAS EG, but couldn't seem to come up with a correct keyword to find
it. No worries, I'm good!
Tom
Super User Tom
Super User

You should be able to change your settings in Enterprise Guide so that it does NOT set the validvarname option to ANY.

 

But you can also just use the PREFIX= option on PROC TRANSPOSE to always add the underscore prefix to the names.  Then the generated names should be the same no matter what setting you have for the validvarname option.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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