Hi there! I'm having a problem and it drives me nuts. 😉 I hope somebody can help me understanding this.
What is it I like to do:
What I show you is a part of a larger program. I just pulled out the statements that bug me. The "real" program does (or should do) the following:
1. It should place all the filenames (with path) in a given forlder in a table called x_dirlist.
(eg: /opt/dir1/dir2/filename_yymmdd.skv.gpg)
2. My program should then for each file that qualifies run a macro that will:
a. Input var for the marco is INPUT_BESTAND
b. Decrypt the file (file name comes in with a .skv.gpg extention)
c. Removed the .gpg extention from the filename (in INPUT_BESTAND) end place the result in a new macro variable IN_BESTAND. The result should be: /opt/dir1/dir2/filename_yymmdd.skv
d. Konvert the file (som values need to be anonymized) that now should reside in IN_BESTAND (ie. with ony the .skv extention)
e. Write it back to the same folder.
Below two examples I played with. One works, the other don't. In the example that doesn't work I removed a lot of statements (the decrypt, convertion etc) that are not relevant for the problem I try to understand.
This works: (the put statements are just inserted so I can see what's in the variables):
%let dir_path = opt/app/sasdata;
%macro test_it(macro_input);
%let input_bestand = &dir_path./¯o_input.;
%put &input_bestand.;
data _null_;
call symput('in_bestand',(tranwrd("&input_bestand.",'.gpg',' ')));
run;
%put &in_bestand.;
%mend;
%test_it(menno.skv.gpg);
%test_it(maximilian.skv.gpg);
LOG:
53 %let dir_path = opt/app/sasdata;
54 %macro test_it(macro_input);
55 %let input_bestand = &dir_path./¯o_input.;
56 %put &input_bestand.;
57 data _null_;
58 call symput('in_bestand',(tranwrd("&input_bestand.",'.gpg',' ')));
59 run;
60 %put &in_bestand.;
61 %mend;
62 %test_it(menno.skv.gpg);
opt/app/sasdata/menno.skv.gpg
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
opt/app/sasdata/menno.skv
63 %test_it(maximilian.skv.gpg);
opt/app/sasdata/maximilian.skv.gpg
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
opt/app/sasdata/maximilian.skv
The following example code does not work for macro variable IN_BESTAND :
%macro get_dirlist;
filename dirlist pipe "ls -p &dir_path. | grep -v /";
data x_dirlist;
length name $100;
infile dirlist;
input name $;
run;
%mend;
%macro convert_file(macro_input);
%let input_bestand = &dir_path./¯o_input.;
%put &input_bestand.;
data _null_;
call symput('in_bestand',(tranwrd("&input_bestand.",'.gpg',' ')));
run;
%put &in_bestand.;
%mend convert_file;
%let incountry = fi;
%let yy = 2015;
%let dir_path = /opt/app/sas94/config/Lev3/SASApp/Data/coredata/delivery/&incountry./freja/STAGED/&yy.;
%get_dirlist;
Data _null_;
Set x_dirlist;
if upcase(substr(name,1,5)) = 'FI03H' then do;
Execmacr = '%convert_file('||strip(name)||')';
Call execute(execmacr);
end;
Run;
So instead of calling the macro manually everytime with a new file name ....:
%convert_file(/opt/dir1/dir2/filename_170131.skv);
%convert_file(/opt/dir1/dir2/filename_170228.skv);
etc.
... I go through a table where the file names reside and call the macro for each file that qualifies.
LOG:
MLOGIC(CONVERT_FILE): Beginning execution.
MLOGIC(CONVERT_FILE): Parameter MACRO_INPUT has value FI03HO_02_2015-09-16_2015-09-30_l305_s1_012.skv.gpg
MLOGIC(CONVERT_FILE): %LET (variable name is INPUT_BESTAND)
SYMBOLGEN: Macro variable DIR_PATH resolves to
/opt/app/sas94/config/Lev3/SASApp/Data/coredata/delivery/&incountry./freja/STAGED/&yy.
SYMBOLGEN: Macro variable INCOUNTRY resolves to fi
SYMBOLGEN: Macro variable YY resolves to 2015
SYMBOLGEN: Macro variable MACRO_INPUT resolves to FI03HO_02_2015-09-16_2015-09-30_l305_s1_012.skv.gpg
MLOGIC(CONVERT_FILE): %PUT &input_bestand.
SYMBOLGEN: Macro variable INPUT_BESTAND resolves to
/opt/app/sas94/config/Lev3/SASApp/Data/coredata/delivery/fi/freja/STAGED/2015/FI03HO_02_2015-09-16_2015-09-30_l305_s1_01
2.skv.gpg
/opt/app/sas94/config/Lev3/SASApp/Data/coredata/delivery/fi/freja/STAGED/2015/FI03HO_02_2015-09-16_2015-09-30_l305_s1_012.skv.gpg
MPRINT(CONVERT_FILE): data _null_;
SYMBOLGEN: Macro variable INPUT_BESTAND resolves to
/opt/app/sas94/config/Lev3/SASApp/Data/coredata/delivery/fi/freja/STAGED/2015/FI03HO_02_2015-09-16_2015-09-30_l305_s1_01
2.skv.gpg
MPRINT(CONVERT_FILE): call
symput('in_bestand',(tranwrd("/opt/app/sas94/config/Lev3/SASApp/Data/coredata/delivery/fi/freja/STAGED/2015/FI03HO_02_2015-09-16_201
5-09-30_l305_s1_012.skv.gpg",'.gpg',' ')));
MPRINT(CONVERT_FILE): run;
MLOGIC(CONVERT_FILE): %PUT &in_bestand.
WARNING: Apparent symbolic reference IN_BESTAND not resolved.
&in_bestand.
MLOGIC(CONVERT_FILE): Ending execution.
I see the same construction here ... but still it doesn't work. I just call the same macro a number of time - once for each file.
Where is my "brain-fart"? 😉
Best regards,
Longimanus 😄
... View more