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 (June 2007, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Wed, 6 Jun 2007 15:03:05 +1000
Reply-To:   "Johnson, David" <David.Johnson@CBA.COM.AU>
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   "Johnson, David" <David.Johnson@CBA.COM.AU>
Subject:   Re: a quicker way to create macro variables
In-Reply-To:   A<200706060441.l564C1il026021@mailgw.cc.uga.edu>
Content-Type:   text/plain; charset="us-ascii"

A statement like this is over coded because the SAS_NAME can be used as the NAME parameter of the Symput() call. i.e. Call Symput( SAS_NAME, Put( INPUT_NAME, Best15.) );

if compress(upcase(sas_name)) = 'KPI_CURRENT_DT' then CALL SYMPUT('KPI_CURRENT_DT', strip(PUT(input_name,$15.)));

If you associate the input names with a type attribute then you can select either the version with the included Put() function, or one that applies the character value directly.

Experiment with the Bestw. Format to ensure the representation is what you want.

I would also not create date parameters in this way. You can derive all these values using some functions and data step logic from a single reference date. It prevents the almost inevitable and hard to find error where you changed all the date parameters except for one, and now the results are wrong.

To be sure, I use a data step to derive the values in variables and then put them to the log to verify what I then store in a macro. It saves a lot of debugging time and some tears later, at the lower cost of a little effort now. Here is an example.

1 Data _NULL_; 2 TODAY = Today(); 3 Put "PNB: dates used in reporting are: "; 4 Put @ 6 "Today " TODAY Date9.; 5 CURRMONTH = IntNx( 'Month', TODAY, 0, 'b'); 6 Put @ 6 "Month started on " CURRMONTH Date9.; 7 Run;

PNB: dates used in reporting are: Today 06JUN2007 Month started on 01JUN2007 NOTE: DATA statement used (Total process time): real time 0.06 seconds

Kind regards

David

"Neque porro quisquam est qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit..."

-----Original Message----- From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of Thien Thai Sent: Wednesday, 6 June 2007 2:41 PM To: SAS-L@LISTSERV.UGA.EDU Subject: a quicker way to create macro variables

Hello SAS users, I'm would like to reduce the coding below to a more succint way of creating macro variables from a SAS data set that looks like this

TODAY 06/06/2007 KPI_current_dt "01JUN2007"d KPI_current_mt 06 Reporting_year 2007 Reporting_mthyr 200706 Prev_Reporting_mthyr 200705 BOM_curr 2007-06-01' BOM_prev 2007-04-01' EOM_curr 2007-06-30' EOM_prev 2007-04-30' BOM_PREV_QTR "01JAN2007"d BOM_CURR_QTR "01APR2007"d EOM_PREV_QTR "31MAR2007"d EOM_CURR_QTR "30JUN2007"d arieswise_connection \\int\arieswise.inc actprod_connection \\int\actprod.inc ftppact_connection \\int\ftppact.inc rlink_ftppact_scr \\int\ftppact.scr SAS_Library H:\sasconnect\WIP\KPI\Data Output H:\sasconnect\WIP\KPI\Output claimState ACT' calendar_start "01JAN2007"d calendar_stop "01JAN2008"d KPI1_target <= 2 KPI2_target <= 5 KPI3_target <= 10 KPI4_target <= 7 KPI5_target <= 20 KPI6_target <= 30 COBRA \\Int\Database KPI7_8_Data Strategy ReviewsTEMP.mdb KPI7_target <= 10 KPI8_target <= 15 KPI9_PASS <= 7 KPI9_REAL_DT < 8 KPI9_target <= 5 KPI10_target KPI11_target <= 0 KPI12_target KPI13_target KPI4_target KPI15_target KPI16_target KPI17_target KPI18_target KPI19_target KPI20_target KPI21_target <= 10

The blank targets are blank for now. I tried to create global macro variables this way (please see below), but I'm sure there are better ways to do this, much appreciated if you can show me how I can make this code more leaner and more efficient.

%MACRO inputs; data _null_; set Inputs; if compress(upcase(sas_name)) = 'KPI_CURRENT_DT' then CALL SYMPUT('KPI_CURRENT_DT', strip(PUT(input_name,$15.))); if compress(upcase(sas_name)) = 'KPI_CURRENT_MT' then CALL SYMPUT('KPI_CURRENT_MT', strip(PUT(input_name,$2.))); if compress(upcase(sas_name)) = 'REPORTING_YEAR' then CALL SYMPUT('REPORTING_YEAR', strip(PUT(input_name ,$4.))); if compress(upcase(sas_name)) = 'REPORTING_MTHYR' then CALL SYMPUT('REPORTING_MTHYR', strip(PUT(input_name,$6.))); if compress(upcase(sas_name)) = 'BOM_CURR' then CALL SYMPUT('BOM_CURR', compress(PUT("'"||input_name,$20.))); if compress(upcase(sas_name)) = 'BOM_PREV' then CALL SYMPUT('BOM_PREV', compress(PUT("'"||input_name,$20.))); if compress(upcase(sas_name)) = 'EOM_CURR' then CALL SYMPUT('EOM_CURR', compress(PUT("'"||input_name,$20.))); if compress(upcase(sas_name)) = 'EOM_PREV' then CALL SYMPUT('EOM_PREV', compress(PUT("'"||input_name,$20.))); if compress(upcase(sas_name)) = 'BOM_PREV_QTR' then CALL SYMPUT('BOM_PREV_QTR', strip(PUT(input_name ,$15.))); if compress(upcase(sas_name)) = 'BOM_CURR_QTR' then CALL SYMPUT('BOM_CURR_QTR', strip(PUT(input_name,$15.))); if compress(upcase(sas_name)) = 'EOM_PREV_QTR' then CALL SYMPUT('EOM_PREV_QTR', strip(PUT(input_name ,$15.))); if compress(upcase(sas_name)) = 'EOM_CURR_QTR' then CALL SYMPUT('EOM_CURR_QTR', strip(PUT(input_name,$15.))); if compress(upcase(sas_name)) = 'ARIESWISE_CONNECTION' then CALL SYMPUT('ARIESWISE_CONNECTION', strip(PUT (input_name ,$250.))); if compress(upcase(sas_name)) = 'ACTPROD_CONNECTION' then CALL SYMPUT('ACTPROD_CONNECTION', strip(PUT(input_name,$250.))); if compress(upcase(sas_name)) = 'FTPPACT_CONNECTION' then CALL SYMPUT('FTPPACT_CONNECTION', strip(PUT(input_name,$250.))); if compress(upcase(sas_name)) = 'RLINK_FTPPACT_SCR' then CALL SYMPUT('RLINK_FTPPACT_SCR', strip(PUT(input_name ,$250.))); if compress(upcase(sas_name)) = 'SAS_LIBRARY' then CALL SYMPUT('SAS_LIBRARY', strip(PUT(input_name ,$250.))); if compress(upcase(sas_name)) = 'OUTPUT' then CALL SYMPUT('OUTPUT', strip(PUT(input_name,$250.))); if compress(upcase(sas_name)) = 'CLAIMSTATE' then CALL SYMPUT('CLAIMSTATE', strip(PUT("'"||input_name,$50.))); if compress(upcase(sas_name)) = 'CALENDAR_START' then CALL SYMPUT('CALENDAR_START', strip(PUT(input_name ,$50.))); if compress(upcase(sas_name)) = 'CALENDAR_STOP' then CALL SYMPUT('CALENDAR_STOP', strip(PUT(input_name,$50.))); if compress(upcase(sas_name)) = 'KPI1_TARGET' then CALL SYMPUT('KPI1_TARGET', strip(PUT(input_name,$10.))); if compress(upcase(sas_name)) = 'KPI2_TARGET' then CALL SYMPUT('KPI2_TARGET', strip(PUT(input_name,$10.))); if compress(upcase(sas_name)) = 'KPI3_TARGET' then CALL SYMPUT('KPI3_TARGET', strip(PUT(input_name,$10.))); if compress(upcase(sas_name)) = 'KPI4_TARGET' then CALL SYMPUT('KPI4_TARGET', strip(PUT(input_name,$10.))); if compress(upcase(sas_name)) = 'KPI5_TARGET' then CALL SYMPUT('KPI5_TARGET', strip(PUT(input_name,$10.))); if compress(upcase(sas_name)) = 'KPI6_TARGET' then CALL SYMPUT('KPI6_TARGET', strip(PUT(input_name,$10.))); if compress(upcase(sas_name)) = 'COBRA' then CALL SYMPUT('COBRA', strip(PUT(input_name,$10.))); if compress(upcase(sas_name)) = 'KPI7_8_DATA' then CALL SYMPUT('KPI7_8_DATA', strip(PUT(input_name,$10.))); if compress(upcase(sas_name)) = 'KPI7_TARGET' then CALL SYMPUT('KPI7_TARGET', strip(PUT(input_name,$10.))); if compress(upcase(sas_name)) = 'KPI8_TARGET' then CALL SYMPUT('KPI8_TARGET', strip(PUT(input_name,$10.))); if compress(upcase(sas_name)) = 'KPI9_PASS' then CALL SYMPUT('KPI9_PASS', strip(PUT(input_name,$10.))); if compress(upcase(sas_name)) = 'KPI9_REAL_DT' then CALL SYMPUT('KPI9_REAL_DT', strip(PUT(input_name,$10.))); if compress(upcase(sas_name)) = 'KPI9_TARGET' then CALL SYMPUT('KPI9_TARGET', strip(PUT(input_name,$10.))); if compress(upcase(sas_name)) = 'KPI10_TARGET' then CALL SYMPUT('KPI10_TARGET', strip(PUT(input_name,$10.))); if compress(upcase(sas_name)) = 'KPI11_TARGET' then CALL SYMPUT('KPI11_TARGET', strip(PUT(input_name,$10.))); if compress(upcase(sas_name)) = 'KPI12_TARGET' then CALL SYMPUT('KPI12_TARGET', strip(PUT(input_name,$10.))); if compress(upcase(sas_name)) = 'KPI13_TARGET' then CALL SYMPUT('KPI13_TARGET', strip(PUT(input_name,$10.))); if compress(upcase(sas_name)) = 'KPI4_TARGET' then CALL SYMPUT('KPI4_TARGET', strip(PUT(input_name,$10.))); if compress(upcase(sas_name)) = 'KPI15_TARGET' then CALL SYMPUT('KPI15_TARGET', strip(PUT(input_name,$10.))); if compress(upcase(sas_name)) = 'KPI16_TARGET' then CALL SYMPUT('KPI16_TARGET', strip(PUT(input_name,$10.))); if compress(upcase(sas_name)) = 'KPI17_TARGET' then CALL SYMPUT('KPI17_TARGET', strip(PUT(input_name,$10.))); if compress(upcase(sas_name)) = 'KPI18_TARGET' then CALL SYMPUT('KPI18_TARGET', strip(PUT(input_name,$10.))); if compress(upcase(sas_name)) = 'KPI19_TARGET' then CALL SYMPUT('KPI19_TARGET', strip(PUT(input_name,$10.))); if compress(upcase(sas_name)) = 'KPI20_TARGET' then CALL SYMPUT('KPI20_TARGET', strip(PUT(input_name,$10.))); if compress(upcase(sas_name)) = 'KPI21_TARGET' then CALL SYMPUT('KPI21_TARGET', strip(PUT(input_name,$10.)));

%GLOBAL KPI_CURRENT_DT KPI_CURRENT_MT REPORTING_YEAR REPORTING_MTHYR BOM_CURR BOM_PREV EOM_CURR EOM_PREV BOM_PREV_QTR BOM_CURR_QTR EOM_PREV_QTR EOM_CURR_QTR ARIESWISE_CONNECTION ACTPROD_CONNECTION FTPPACT_CONNECTION RLINK_FTPPACT_SCR PERM_LIBRARY OUTPUT CLAIMSTATE CALENDAR_START CALENDAR_STOP KPI1_TARGET KPI2_TARGET KPI3_TARGET KPI4_TARGET KPI5_TARGET KPI6_TARGET COBRA KPI7_8_DATA KPI7_TARGET KPI8_TARGET KPI9_PASS KPI9_REAL_DT KPI9_TARGET KPI10_TARGET KPI11_TARGET KPI12_TARGET KPI13_TARGET KPI4_TARGET KPI15_TARGET KPI16_TARGET KPI17_TARGET KPI18_TARGET KPI19_TARGET KPI20_TARGET KPI21_TARGET; run; %MEND inputs; %inputs;

************** IMPORTANT MESSAGE ***************************** This e-mail message is intended only for the addressee(s) and contains information which may be confidential. If you are not the intended recipient please advise the sender by return email, do not use or disclose the contents, and delete the message and any attachments from your system. Unless specifically indicated, this email does not constitute formal advice or commitment by the sender or the Commonwealth Bank of Australia (ABN 48 123 123 124) or its subsidiaries. We can be contacted through our web site: commbank.com.au. If you no longer wish to receive commercial electronic messages from us, please reply to this e-mail by typing Unsubscribe in the subject line. **************************************************************


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