LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (February 2003, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Thu, 6 Feb 2003 16:02:16 -0500
Reply-To:     Sigurd Hermansen <HERMANS1@WESTAT.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Sigurd Hermansen <HERMANS1@WESTAT.COM>
Subject:      Re: A simple Macro Question
Comments: To: John Hewitt <john_hewitt2003@YAHOO.COM>
Content-Type: text/plain; charset="iso-8859-1"

This little program illustrates several key concepts in SAS Macroprogramming:

data ZWAV_date_range; input month_yr: $char7.; cards; 1999Jun 2003Feb 2002Jun ; run; %let yyyymmm=%upcase(2003Feb); %macro reFmt(yyyymmm); %global month_yr; %let month_yr=%substr(&yyyymmm,5,3)%substr(&yyyymmm,1,4); %put &month_yr ; proc sql noprint; select put(max(input(substr(month_yr,5,3)||substr(month_yr,1,4),monyy7.)),monyy7.) into: max_month_key from ZWAV_date_range ; quit; %put &max_month_key ; %if &max_month_key NE &month_yr %then %put=&max_month_key; %mend reFmt; %reFmt(&yyyymmm)

1. Concatenation of macrovariable values does not require a concatenation operator; 2. It pays to simplify macroprograms; 3. Even if you simply a macroprogram, it pays to check for surprises (eg., case sensitivity of comparisons of macrovariables).

Sig

-----Original Message----- From: John Hewitt [mailto:john_hewitt2003@YAHOO.COM] Sent: Thursday, February 06, 2003 10:40 AM To: SAS-L@LISTSERV.UGA.EDU Subject: A simple Macro Question

Dear All:

I have written a macro to compare to compare the current month with the highest month from a SAS dataset which is given below.It does not work because where as I do get a value from select statement in Proc SQL because it is executed I don't get any value from %let month_yr=month(input(&yyyymmm, monyy7.))) because month_yr is a macro variable and it expects a character value.

How do I get around this?

Thanks in advance for your help.

John

%Macro checkdate;

%let start="31jan2003"d;

%do i=1 %to 1;

data _null_;

call symput('yyyymmm',put(intnx('month',&start,&&i-1),yymon7.));

run;

proc sql;

select max(month(input(substr(month_yr,5,3)||substr(month_yr,1,4),monyy7.)))

into: max_month_key

from da_clen.ZWAV_date_range;

quit;

%let month_yr=month(input(&yyyymmm, monyy7.)));

%if &max_month_key NE month_yr %then %put=&max_month_key;

%end;

%mend checkdate;

%checkdate

--------------------------------- Do you Yahoo!? Yahoo! Mail Plus - Powerful. Affordable. Sign up now


Back to: Top of message | Previous page | Main SAS-L page