2
votes

I wrote this macro in sas to have some information about some files :

%macro info_1(cmd);
      filename dirList pipe &cmd.;

      data work.dirList;
            infile dirList length=reclen;
            input file $varying200. reclen;
            permission=scan(file,1,"");
            if input(scan(file,2,""), 8.)=1;
            user=scan(file,3,"");
            group=scan(file,4,"");
            file_size_KB=round(input(scan(file,5,""), 8.)/1024,1);
            file_size_MB=round(input(scan(file,5,""), 8.)/1024/1024,1);
            modified_time=input(catx(" ",scan(file,6," "),scan(file,7,"")),anydtdtm.);
            date_mod = datepart(modified_time);
            time_zone=scan(file,8,"");
            file_name=scan(file,-1,"");
            format modified_time datetime19.;
            format file_size_MB comma9.;
            format date_mod date9.;
            run;

%mend info_1;

then i declare this macro variable:

%let cmd = ls --full-time;
%let sep1= %quote( );
%let path = /data/projects/flat_file/meteo ; 
%let file = *.json ;
%let sep2 = %quote(/) ;
%let fullpath = &cmd.&sep1.&path.&sep2.&file;

Then i try to execute the macro :

%info_1(&fullpath.);

And i see a strange thing. I post a image because it is impossible to describe it. I guess that there are special chars.

Screenshot

How to fix that thing?

1
What is with all of the %quotes?Joe
Also: what are the point of the &sep characters. They seem pointless. What's the reason for having those as macro variables, instead of just %let fullpath=&cmd. &path./&file.; ?Joe
@joe it doesn't work. When i try to put the variable fullpath on the screen i don't see nothing.Pierpaolo Paolini
Interesting. It's the * - the macro parser has some trouble with that, and seems to think that is a comment I think. Weeeird.Joe

1 Answers

3
votes

Inside your macro I believe you just need to add quotes around this line:

filename dirList pipe &cmd.;

Right now after the macro resolution is happening it is treating it like:

filename dirList pipe ls --full-time;

... which is treating the ls part onwards like parameters to the filename statement. When fixed the code should appear as:

filename dirList pipe "&cmd";

Which will then be resolved as:

filename dirList pipe "ls --full-time";