BookmarkSubscribeRSS Feed
polingjw
Quartz | Level 8

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.

3 REPLIES 3
Ksharp
Super User

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

polingjw
Quartz | Level 8

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.

Ksharp
Super User

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

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 810 views
  • 0 likes
  • 2 in conversation