BookmarkSubscribeRSS Feed
Kayla_Tan222
Calcite | Level 5

 

Hi all, I am facing a problem of my if statement is not work in the Do loop. This cause my ods html does not work and I cant print out my result. Did I type anything wrong? 

 

The log summary does not have any error. But just the result does not printed out.

 

 

 

 

 

%macro date(YYYY=2019,MM=02,Y=2019,M=02);%global YR accyrfy MTH accmthfy acmthfy1 acmthfy2 fileyear accyrfy1 filemth;

 

 

libname pl&Y&M. "\\kaiwksgh415thw5\Data\POLA\Claim\&Y\&Y&M\DBF";

Data pl&Y&M..POLA_clm_3months_&Y&M.;

set pl&Y&M..POLA_clm_agg_&Y&M.;

 

 

.........................................(BODY)

 

 

 

%macro financial (MONTH);

%do i=&acmthfy1. %to &MONTH;

%if &i.=1 %THEN %DO;

%let filemth=12;

%end;

 

%else %if &i.=12 %then %do;

%let filemth=11;

%end;

 

%else %if &i.=11 %then %do;

%let filemth=10;

%end;

 

%else %do;

%let filemth=0%eval(&i.-1);

%end;

 

 

/*****************************PD*****************************/

PROC SQL;

create table SMCD_PD_&fileyear&filemth. AS

SELECT put(zmajrsk,$class.) as class, dev11yr_fy,sum(zclmpd) AS zclmpd

FROM pl&Y&M..POLA_clm_3months_&Y&M.

WHERE ACCYR_FY=&accyrfy1. & accmth_fy=&i.

GROUP BY class,2;

 

run;

ods html

file="\\kaiwksgh415thw5\Data\POLA\Claim\&fileyear\&fileyear&filemth\result\SMCD_mth_PD_FY_10DY_&fileyear&filemth..html"

 

style=normal;

proc print;

run;

 

%end;

%mend financial;

%financial(&acmthfy2.);

 

 

 

 

%mend date;

%date(YYYY=2019,MM=02,Y=2019,M=02);

run;

 

1 REPLY 1
Kurt_Bremser
Super User

The "inner" (keep in mind that nested/hierarchical macro definitions are not possible in SAS, all macros exist in the global symbol table) macro definition for financial() has no real purpose; you only call it once with one parameter.

Remove that definition (and call), and code your %do with the real parameter:

%do i=&acmthfy1. %to &acmthfy2.;

Add %put statements to reveal the state of your macro variables at critical stages.

Make your calculation of filemth simpler:

%if i = 1
%then %let filemth=12;
%else %let filemth=%sysfunc(putn(&i.-1,z2.));

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
  • 1 reply
  • 392 views
  • 0 likes
  • 2 in conversation