Pass Dataset Value to Macro or Options

Reply
N/A
Posts: 1

Pass Dataset Value to Macro or Options

Hi,

Can anybody offer any solutions to fix the below. I can do it myself by putting the majority of the code inside a macro and calling the macro, but would like to know if there is a non macro way to do it.

Data Captured_Vals;

   Do DS_Val = 1 To 10;

      Ret_Val = %Macro( Lib.Cluster ( MemNum = DS_Val ) );

      Output;

   End;

Run;

         OR

Data Captured_Data;

   DS_Val = 99;

       Set Lib.Cluster ( MemNum = DS_Val );

Run;

Hopefully from the highlights, it's obvious what I'm trying to do, but just in case. I'm trying to pass a dataset value (DS_Val) to either an option within a set statement or an option within a macro ran within a datastep.

TIA.

Super User
Posts: 5,260

Re: Pass Dataset Value to Macro or Options

Well, it's not clear what you really want to do (or why)?

I'm guessing that you want to read certain members from a SPDS libname, right?

I don't know how you want to supply the numbers, do you want to store several menum in the same captured_data table?

And why do you want to extract data based on memnum at all?

Data never sleeps
Super User
Super User
Posts: 6,502

Re: Pass Dataset Value to Macro or Options

I cannot figure out what purpose the sample code could serve, but if you want to make a piece of code a variable you do not need to create a macro, just assign the value to a macro variable and reference it where it is needed.

%let varname=ds_val ;

data captured_vals;

   do &varname = 1 to 10;

      ret_val = resolve(cats('%mymac( lib.cluster ( memnum =',&varname,'))'));

      output;

   end;

run;

data captured_data;

   &varname = 99;

   set lib.cluster ( memnum = &varname );

run;

Ask a Question
Discussion stats
  • 2 replies
  • 164 views
  • 0 likes
  • 3 in conversation