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

Hi all,

 

I am trying to get a macro call to output each new set of conditions in a datastep (not sure if im explaining that right!), but it's outing observations meeting the first condition.  I think it has something to do with where I'm calling the macro or macro can't override another...I have no idea. So right now, I only get 4 observations meeting the first conditons (the 'PRE').   Here is my code, would appreciate any help! 


 %macro zg (t, zgvar, stat,test, cd, orres, unit);

  	if LBJTPT&t ^='' and &zgvar ^='' then do;
	
	  zgtpt=strip(LBJTPT&t);
	  zgtptnum=&t;

	  LBJPHc= strip(put(LBJPH&t,best.));
	  LBJTEMPc=strip(put(LBJTEMP&t,best.));

	  zgstat=&stat;
	  zgtest= &test;
	  zgtestcd=&cd;
	  zgorres= &orres;
	  zgorresu= &unit;
	  if lbjdat ^=. then ZGDTC=put(lbjdat, is8601da.);
	  output;
	  end; 
	  %mend zg;

data tpt1;
length usubjid $19 zgtest zgtestcd zgorres zgtpt zgstat zgtpt $100 zgdtc zgorresu $50 ;
set db.lbj (where=(lbjperf_display='Yes' and formname ^= 'BLANK'));

  if not missing(subject) then usubjid = 'PVP101-01-' || Strip(subject);

  	%zg (1,LBJND1_DISPLAY, 'NOT DONE', 'Not Done Pre', 'ZGPRE', '','' );
	%zg (1,LBJPHc, '', 'pH', 'pH', LBJPHc,'' );
	%zg (1,LBJTEMPc, '', 'Temperature', 'TEMP', LBJTEMPc, LBJTEMPU1_DISPLAY);

keep usubjid zgtest zgtestcd zgorres zgtpt zgstat zgtpt zgdtc zgorresu zgtptnum;
run;

 And to REAAALLLY help me out,   I trying to figure out how to loop this macro to output as each timepoint 't' changes


 %macro zg (t, zgvar, stat,test, cd, orres, unit);

  	if LBJTPT&t ^='' and &zgvar ^='' then do;
	
	  zgtpt=strip(LBJTPT&t);
	  zgtptnum=&t;

	  LBJPHc= strip(put(LBJPH&t,best.));
	  LBJTEMPc=strip(put(LBJTEMP&t,best.));

	  zgstat=&stat;
	  zgtest= &test;
	  zgtestcd=&cd;
	  zgorres= &orres;
	  zgorresu= &unit;
	  if lbjdat ^=. then ZGDTC=put(lbjdat, is8601da.);
	  output;
	  end; 
	  %mend zg;

data tpt1;
length usubjid $19 zgtest zgtestcd zgorres zgtpt zgstat zgtpt $100 zgdtc zgorresu $50 ;
set db.lbj (where=(lbjperf_display='Yes' and formname ^= 'BLANK'));

  if not missing(subject) then usubjid = 'PVP101-01-' || Strip(subject);

  	%zg (1,LBJND1_DISPLAY, 'NOT DONE', 'Not Done Pre', 'ZGPRE', '','' );
	%zg (1,LBJPHc, '', 'pH', 'pH', LBJPHc,'' );
	%zg (1,LBJTEMPc, '', 'Temperature', 'TEMP', LBJTEMPc, LBJTEMPU1_DISPLAY);

keep usubjid zgtest zgtestcd zgorres zgtpt zgstat zgtpt zgdtc zgorresu zgtptnum;
run;



/***NEED TO GET THESE TO OUTPUT WITH EACH TIMEPOINT CHANGE***/




	%zg (2,LBJND2_DISPLAY, 'NOT DONE', 'Not Done Post 15', 'ZGPOST15', '','' );
	%zg (2,LBJPHc, '', 'pH', 'pH', LBJPHc,'' );
	%zg (2,LBJTEMPc, '', 'Temperature', 'TEMP', LBJTEMPc, LBJTEMPU2_DISPLAY);

	%zg (3,LBJND3_DISPLAY, 'NOT DONE', 'Not Done Post 20', 'ZGPOST20', '','' );
	%zg (3,LBJPHc, '', 'pH', 'pH', LBJPHc,'' );
	%zg (3,LBJTEMPc, '', 'Temperature', 'TEMP', LBJTEMPc, LBJTEMPU3_DISPLAY);

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

First figure out what code you want to generate. Then figure how (if) using a macro can help you generate that code.

 

Since you already have a macro you can run it with MPRINT option turned on so that you can see a copy of the code it generates.  Does that code look like what you thought it would generate? 

 

Since you say it doesn't do what you want copy the generated coded and make a program.  Then adjust the program until it does work.  Then modify the macro to generate the code that works.

View solution in original post

2 REPLIES 2
Tom
Super User Tom
Super User

First figure out what code you want to generate. Then figure how (if) using a macro can help you generate that code.

 

Since you already have a macro you can run it with MPRINT option turned on so that you can see a copy of the code it generates.  Does that code look like what you thought it would generate? 

 

Since you say it doesn't do what you want copy the generated coded and make a program.  Then adjust the program until it does work.  Then modify the macro to generate the code that works.

ballardw
Super User

Without data haven't a clue what this is supposed to actually do.

 

I wonder if maybe in your macro isn't part of the issue. You make 3 calls with &t=1. So for each of those with the same value of &t the generated code is exactly the same.

 

 

if LBJTPT&t ^='' and &zgvar ^='' then do;
	
	  zgtpt=strip(LBJTPT&t);
	  zgtptnum=&t;

	  LBJPHc= strip(put(LBJPH&t,best.));
	  LBJTEMPc=strip(put(LBJTEMP&t,best.));

And this indicates you have something in a wide format to have multiple variables with the same suffix you are representing with t.

Perhaps transposing the data could remove the need to parse across the blocks of variables.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 2 replies
  • 497 views
  • 1 like
  • 3 in conversation