BookmarkSubscribeRSS Feed
GA_Mike
Calcite | Level 5

Hello,

My code looks similar to this:

%Macro CFT(PGM,ID);

  PROC SQL;

  CREATE TABLE work.tempRV AS

  SELECT DISTINCT RV

  from work.SPECS a

  WHERE a.Revision = &ID.;

  PROC SQL;

  SELECT cats(count(*))

  into :MAXRV

  FROM work.tempRV;

    

  proc sql;

  select DISTINCT RV

  into :RV1-:RV&MAXRV.

  from work.tempRV;

  quit;

%Mend;

When the macro is called, the first PROC SQL runs as expected but the second and third do not execute.  Any help would be greatly appreciated.

Thanks,

5 REPLIES 5
ballardw
Super User

Do the steps run if you do not use macro code? Does work.tempRV actually have any records?

I do question why use the cats(count(*)) structure as it shouldn't be any different than count(*).

And if the code is similar it isn't identical so we may not be much help.

GA_Mike
Calcite | Level 5

They do run if they are outside of the macro. 

work.tempRV does contain records.

I can't remember why I switched from count(*) to cats(count(*)). There was something in the data that was causing an issue and that is how I resolved it. 

By similar what I mean is that I changed the permanent library names to 'work' just to try to avoid confusion.

GA_Mike
Calcite | Level 5

Ok.  I found the reason for cats(count(*)) in my notes.  If I only used count(*) in the third PROC SQL the definition of the macro variable RV errors due to leading spaces.

proc sql;

  select DISTINCT RV

  into :RV1-:RV&MAXRV.    <-- So right here instead of resolving to   into :RV1-:RV10       it does this  into :RV1-:RV     10  and errors.

  from work.tempRV;

  quit;

Reeza
Super User

You have a scope problem, I'm guessing. The macro variables are created in the process but are not available afterwards.

%Macro CFT(ID=);

  PROC SQL;

  CREATE TABLE work.tempRV AS

  SELECT DISTINCT name

  from sashelp.class a

  WHERE sex = "&ID.";

proc sql;

  SELECT cats(count(*))

  into :MAXRV

  FROM work.tempRV;

  proc sql;

  select DISTINCT name

  into :RV1-:RV&MAXRV.

  from work.tempRV;

  quit;

%put &rv1.;

%put &maxrv;

%put &&&rv&maxrv.;

%Mend;

%cft(ID=F);

%put &rv1.;

%put &maxrv;

%put &&&rv&maxrv.;

Astounding
PROC Star

Reeza has the right idea here.

PROC SQL runs every time (with complications if the incoming data set happens to be empty).  It creates your macro variables.  However, it always creates them in the LOCAL symbol table.  By the time you try to use them, %CFT has finished executing and its LOCAL symbol table has been erased automatically.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 5 replies
  • 1007 views
  • 0 likes
  • 4 in conversation