BookmarkSubscribeRSS Feed
CathyB
Calcite | Level 5

 

Newbie here, so my references come from the spreadsheet world.  I'm learning, though.

 

I have a table from a DESCRIPT step that has created my inputs for a chart.  But I will have many of these such tables I will combine, so I need a way to identify the source table which is a variable since it will eventually be part of a macro. But for now, my incoming dataset is hardcoded as Z_HCCOVR.

 

The output will be Z_HCCOVR2, and that works fine, but it contains not only the TabName field, but the dataset name as another field, both unpopulated.   TableNo is a field known to be populated.

 

Using examples from other community replies, I have the following, which doesn't work. 

 

Where am I going wrong?

 

%let VAR = Z_HCCOVR;

 

data &var.2;
     set &var;       
length TabName $15;
       where XYZ ne 0;     
if tablelno ne . then
do;
TabName = pathname(&var);
end;
run;

 

Many thanks to all who contribute to this community.  I've learned a lot from you.

 

Cathy

4 REPLIES 4
Tom
Super User Tom
Super User

First thing is to learn how to use SAS code before trying to use macro code, even simple macro variables.

 

The PATHNAME function wants a LIBREF or a FILEREF to operate on. 

 

You called it this way:

pathname(Z_HCCOVR);

So that says take the value of the variable named Z_HCCOVR and then look for a FILEREF or a LIBREF with that name and return the physical path that it point to.

 

What are you actually trying to do?

CathyB
Calcite | Level 5

Clearly, I'm trying to run before I can walk.

 

I would like to insert the incoming dataset name into the  output dataset as a variable to be able to identify the source data.

 

Cathy

Tom
Super User Tom
Super User
Depends on how it is INCOMING. If you are using a SET statement in a DATA STEP then you can use the INDSNAME= option of the SET statement.
Look it up in the documentation.
Reeza
Super User

There's an easier option. When you're combining multiple data sets at once, in this case I'm assuming via SET statements there's the IN option. One word of caution when learning SAS, make sure to search here first and limit to answers from previous 5 or 10 years. With an old language you can find results that are old and don't reflect the current state of the software. 

 

Run the code and see the variable named input_data_source. 

 

 

data want;
set sashelp.class sashelp.air indsname = source;

input_data_source = source;
run;

@CathyB wrote:

 

Newbie here, so my references come from the spreadsheet world.  I'm learning, though.

 

I have a table from a DESCRIPT step that has created my inputs for a chart.  But I will have many of these such tables I will combine, so I need a way to identify the source table which is a variable since it will eventually be part of a macro. But for now, my incoming dataset is hardcoded as Z_HCCOVR.

 

The output will be Z_HCCOVR2, and that works fine, but it contains not only the TabName field, but the dataset name as another field, both unpopulated.   TableNo is a field known to be populated.

 

Using examples from other community replies, I have the following, which doesn't work. 

 

Where am I going wrong?

 

%let VAR = Z_HCCOVR;

 

data &var.2;
     set &var;       
length TabName $15;
       where XYZ ne 0;     
if tablelno ne . then
do;
TabName = pathname(&var);
end;
run;

 

Many thanks to all who contribute to this community.  I've learned a lot from you.

 

Cathy


 

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
  • 4 replies
  • 575 views
  • 0 likes
  • 3 in conversation