DATA Step, Macro, Functions and more

Timing Problem

Reply
Regular Contributor
Posts: 171

Timing Problem

If you have a DATA step view with a SET statement, where the data sets to be referenced in the SET statement are stored in a macro variable, is it possible to resolve this macro variable at execution time?  For example:

%let ds=sashelp.class;

data ds/view=ds;

     set &ds;

run;

%let ds=sashelp.shoes;

proc print data=ds(obs=3);

run;

Of course, the above code prints the first three records of the sashelp.class data set.  Is it possible to define the view in such a way that the first three observations in sashelp.shoes are printed instead?  Thanks in advance for your input.

Super User
Posts: 9,676

Re: Timing Problem

I think you can't do it because view only stores the statements of dataset. you can't change it as performing. It is static.

data ds/view=ds;

     set &ds;

run;

%let ds=sashelp.class;

%let ds=sashelp.shoes;

proc print data=ds(obs=3);

run;

These code will generate Errors.

But Why not useing Macro to instead of the view if you need to change the dataset as performing.

Using:

data view=ds ;

describe;

run;

to see what code exactly stored in the view.

Ksharp

Regular Contributor
Posts: 171

Re: Timing Problem

Thanks Ksharp.   If the macro variable reference is part of an expression or an assignment statement, you can resolve it at execution time using the SYMGET or RESOLVE functions.  For example:

%let sex=M;

data class/view=class;

     set sashelp.class;

     where sex=symget('sex');

run;

%let sex=F;

proc print data=class(obs=3);

run;

The problem is that I want to use the macro variable in a SET statement instead of in an expression or assignment statement.

I know that there are many alternative solutions, such as writing a macro.  I posed the question just out of curiosity, not necessity.  As you said, it might not be possible.

Thanks again.

Super User
Posts: 9,676

Re: Timing Problem

Hi.

As I said, VIEW only stores the data step statement. Once you stored it , you can change it any more.

For your situation, You can't change the dataset 's name in the data step.

Ksharp

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