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 (July 2007, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Wed, 18 Jul 2007 19:50:19 +0000
Reply-To:     toby dunn <tobydunn@HOTMAIL.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         toby dunn <tobydunn@HOTMAIL.COM>
Subject:      Re: dynamically assigning values to macro variabel
Comments: To: rune@FASTLANE.NO
In-Reply-To:  <KJWdnYS-a_nS-wPbRVnzvQA@telenor.com>
Content-Type: text/plain; format=flowed

Rune ,

The put function has a third aregument that is seldom used by the masses bu very handy that argument can be :

-L = Left Align -C = Center Align -R = Right Align

it is the justification for the resulting value.

Toby Dunn

If anything simply cannot go wrong, it will anyway. Murphys Law #2.

The buddy system is essential to your survival; it gives the enemy somebody else to shoot at. Murphys Law #

Tell a man there are 300 billion stars in the universe and he'll believe you. Tell him a bench has wet paint on it and he'll have to touch to be sure. Murphys Law #9

From: Rune Runnestø <rune@FASTLANE.NO> Reply-To: Rune Runnestø <rune@FASTLANE.NO> To: SAS-L@LISTSERV.UGA.EDU Subject: Re: dynamically assigning values to macro variabel Date: Wed, 18 Jul 2007 21:13:13 +0200

Gerhard and Ian put me on some good ideas. As toby says, I owe you an explanation

I am testing 4 different files. If the record length wihtin each file is the same for all records in that file. The result of the testing is written to the log. Either as ERROR messsages in red or - if everything is OK - as blue NOTES.

*Testar recordlengden i datafila AKSJER; data _null_; infile aksjer lrecl = &rl_aksjer end = lastrec; file f01; input; if length(_infile_) ne &rl_aksjer then do; put _infile_; teller +1; end; if lastrec then do; if teller > 0 then do; error "ERROR: *********************************************************"; error "ERROR: "; error "ERROR: I fila &f_aksjer har ikkje alle records lik postlengde"; error "ERROR: "; error "ERROR: *********************************************************"; end; else if teller eq 0 then do; error "NOTE: *******************************************************"; error "NOTE: "; error "NOTE: I fila &f_aksjer har alle records lik postlengde"; error "NOTE: "; error "NOTE: *******************************************************"; end; end; run;

*Testar recordlengden i datafila ANSATTE; data _null_; infile ansatte lrecl = &rl_ansatte end = lastrec; file f02 lrecl = &rl_ansatte; input; if length(_infile_) ne &rl_ansatte then do; put _infile_; teller +1; end; if lastrec then do; if teller > 0 then do; error "ERROR: *********************************************************"; error "ERROR: "; error "ERROR: I fila &f_ansatte har ikkje alle records lik postlengde"; error "ERROR: "; error "ERROR: *********************************************************"; end; else if teller eq 0 then do; error "NOTE: *******************************************************"; error "NOTE: "; error "NOTE: I fila &f_ansatte har alle records lik postlengde"; error "NOTE: "; error "NOTE: *******************************************************"; end; end; run;

*Testar recordlengden i datafila KODER; data _null_; infile koder lrecl = &rl_koder end = lastrec; file f03; input; if length(_infile_) ne &rl_koder then do; put _infile_; teller +1; end; if lastrec then do; if teller > 0 then do; error "ERROR: *********************************************************"; error "ERROR: "; error "ERROR: I fila &f_koder har ikkje alle records lik postlengde"; error "ERROR: "; error "ERROR: *********************************************************"; end; else if teller eq 0 then do; error "NOTE: *******************************************************"; error "NOTE: "; error "NOTE: I fila &f_koder har alle records lik postlengde"; error "NOTE: "; error "NOTE: *******************************************************"; end; end; run;

*Testar recordlengden i datafila SKATTER; data _null_; infile skatter lrecl = &rl_skatter end = lastrec; file f04 lrecl = &rl_skatter; input; if length(_infile_) ne &rl_skatter then do; put _infile_; teller + 1; end; if lastrec then do; if teller > 0 then do; error "ERROR: *********************************************************"; error "ERROR: "; error "ERROR: I fila &f_skatter har ikkje alle records lik postlengde"; error "ERROR: "; error "ERROR: *********************************************************"; end; else if teller eq 0 then do; error "NOTE: *******************************************************"; error "NOTE: "; error "NOTE: I fila &f_skatter har alle records lik postlengde"; error "NOTE: "; error "NOTE: *******************************************************"; end; end; run;

Instead of this repetitive code, I have managed to only 25 % of codelines. If there had been 20 files to test, the advantage of the code below would have increased.

%macro tp01_tfp_genfiler; data _null_; set &lib..__testskjema; where testpunkt eq '01'; call symput ("nr", _n_); call symput ("filnamn"!!put(_n_, 8. -L), compress(filnamn)); call symput ("reclen_fil"!!put(_n_, 8. -L), compress(reclen_fil)); call symput ("filnamn_ut"!!put(_n_, 8. -L), compress(filnamn_ut)); run;

%do i = 1 %to &nr; data _null_; call execute ("data _null_;" ); call execute (" infile &&filnamn&i lrecl = &&reclen_fil&i end = lastrec;" ); call execute (" file &&filnamn_ut&i ;" ); call execute (" input;" ); call execute (" if length (_infile_) ne &&reclen_fil&i then do; " ); call execute (" put _infile_;" ); call execute (" teller +1;" ); call execute (" end;" ); call execute (" if lastrec then do;" ); call execute (" if teller > 0 then do;" ); call execute (" error 'ERROR: *********************************************************';" ); call execute (" error 'ERROR: ';" ); call execute (" error 'ERROR: I fila &&filnamn&i har ikkje alle records lik postlengde;'" ); call execute (" error 'ERROR: ';" ); call execute (" error 'ERROR: *********************************************************';" ); call execute (" end;" ); call execute (" else if teller eq 0 then do;" ); call execute (" error 'NOTE: *********************************************************';" ); call execute (" error 'NOTE: ';" ); call execute (" error 'NOTE: I fila &&filnamn&i har alle records lik postlengde;'" ); call execute (" error 'NOTE: ';" ); call execute (" error 'NOTE: *********************************************************';" ); call execute (" end;" ); call execute (" end;" ); call execute ("run;"); run; %end; %mend;

%tp01_tfp_genfiler;

I am using the table __TESTSKJEMA as a collection of metadata. And the macro variables obtain their values from these metadata.

There is one little thing I wonder about, call symput ("filnamn_ut"!!put(_n_, 8. -L), compress(filnamn_ut)); - what does the '-L' mean ?

Rune

_________________________________________________________________ http://imagine-windowslive.com/hotmail/?locale=en-us&ocid=TXT_TAGHM_migration_HM_mini_pcmag_0507


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