BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
David_Billa
Rhodochrosite | Level 12
We are near to the answer I believe. After we create the list macro
variables from your initial program, how to use those macro variables
dynamically as arguments in %index function?

For example, I have the files in one folder as I mentioned in my post, I
want to check if the file has a string which matches with our values of our
macro variables. If it matches then move the files to another folder.

Hope it helps.
Kurt_Bremser
Super User

Create two datasets: one with the filenames, the other with the periods you're looking for. Join them, and use the result to do the file copy. No macro variables and no macro code needed at all.

David_Billa
Rhodochrosite | Level 12
I want to do it in a macro as I want to update the existing program which
has macros. I was not allowed to use other than macros.
ballardw
Super User

@David_Billa wrote:
I want to do it in a macro as I want to update the existing program which
has macros. I was not allowed to use other than macros.

Another instance of a boss with the "I don't care that a saw is the best tool, use a chisel because I say so!" attitude perhaps?

Tom
Super User Tom
Super User

@David_Billa wrote:
I want to do it in a macro as I want to update the existing program which
has macros. I was not allowed to use other than macros.

Right now I have NO idea what you want. You need to explain WHAT you are trying to do.  Show a simple example of two or three macro variables with realistic values.  Then show what SAS code you need to produce using those macro variable values.  Then we can show you the proper syntax.  

ballardw
Super User

@David_Billa wrote:

@Tom @Kurt_Bremser 

 

I need a  need a list of macro variables, but a macro variable with a value and b macro variable with b value and so on.

So how to pass these macro variables as arguments to %index function?


The way you phrase this feels to me like you may have had an idea and unwilling to consider other approaches, even if easier or more maintainable.

 

Any thing with a "list of macro variables" can depend a lot on what the list actually looks like. If a simple space delimited list of single strings then you can pull each individual value from from the list with something like this:

 

%macro dummy(list = );
%do i = 1 %to %sysfunc(countw(&list.));
   %let parm = %scan(&list.,&i.);
   %put Parm number &i. is &parm.;
%end;
%mend;

%dummy(list= first second other garbage);

So you could stick Parm, or whatever you want to call it in any function, data set or external filename, title text ...

David_Billa
Rhodochrosite | Level 12

@Kurt_Bremser I just noticed that the name of the dataset which has been created from your program is 'name' instead of 'files'. How it is possible as you started your program with 'data files'?

Kurt_Bremser
Super User

Please post the log from the code that created a dataset "name".

If you are working through Enterprise Guide and use "Submit Selection", it can be that EG thinks a previously created dataset is part of the recent submission, and includes it in the resulting dataset list.

David_Billa
Rhodochrosite | Level 12

@Kurt_Bremser Yes, I ran via EG. I tried with new session as well, but still name of the dataset is created with 'name' instead of 'files' as my code starts with 'data files'. Log also says the same but name of the dataset is created with 'name'

 

May I know how to resolve this issue? I never seen this issue before.

 

NOTE: The data set WORK.FILES has 3 observations and 1 variables.
NOTE: Compressing data set WORK.FILES increased size by 100.00 percent. 
      Compressed is 2 pages; un-compressed would require 1 pages.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds

 

 

 

Tom
Super User Tom
Super User

If you are running macros (not just using macro variables) then you should turn on the MPRINT option so you can see in the SAS log what code your macro generated.  That should help you.  If it is still confusing (or you are not actually running a macro) then you might want to turn on the option SYMBOLGEN.  But if your program references a lot of macro variables that can quickly make the SAS log hard to read. 

David_Billa
Rhodochrosite | Level 12
I didn't use macro in my code as I want to test in data step first where I
found this issue. How to debug this issue in data step?
Tom
Super User Tom
Super User

@David_Billa wrote:
I didn't use macro in my code as I want to test in data step first where I
found this issue. How to debug this issue in data step?

If you think you have a bug in Enterprise Guide and can re-create it with a simple data step then report it to SAS support.

Shmuel
Garnet | Level 18

@David_Billa wrote:

@Kurt_Bremser Yes, I ran via EG. I tried with new session as well, but still name of the dataset is created with 'name' instead of 'files' as my code starts with 'data files'. Log also says the same but name of the dataset is created with 'name'

 

May I know how to resolve this issue? I never seen this issue before.

 

NOTE: The data set WORK.FILES has 3 observations and 1 variables.
NOTE: Compressing data set WORK.FILES increased size by 100.00 percent. 
      Compressed is 2 pages; un-compressed would require 1 pages.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds

 

 

 


The log part you posted is a proof that the file is named "work.files", that means either you are looking on a different data set or there is a step that renames the data set.

 

You were asked to post the full log, which includes the code and any later step up the the minute you saw a data set named "name". Check their datetime of creation - does is fit the log ?!

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 28 replies
  • 4233 views
  • 13 likes
  • 6 in conversation