DATA Step, Macro, Functions and more

Name of previous dataset

Accepted Solution Solved
Reply
Contributor
Posts: 46
Accepted Solution

Name of previous dataset

I know if I put the following Proc Print in my code, it will print the data for the last dataset created (previous dataset):

Proc print;

run;

But what I'd really like to do is put that in a macro with that grabs the name of the last dataset created and puts it into a TITLE statement. Is there a way to know the name of the dataset that was created?

Thanks,

J


Accepted Solutions
Solution
‎04-20-2012 11:14 AM
PROC Star
Posts: 7,474

Re: Name of previous dataset

Posted in reply to JasonDiVirgilio

Have you tried using the automatically created macro variable: &sysdsn. ?

There are a lot of automatically created macro variables that capture things you might want.  Take a look at: http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/viewer.htm#a001071968.htm

View solution in original post


All Replies
Solution
‎04-20-2012 11:14 AM
PROC Star
Posts: 7,474

Re: Name of previous dataset

Posted in reply to JasonDiVirgilio

Have you tried using the automatically created macro variable: &sysdsn. ?

There are a lot of automatically created macro variables that capture things you might want.  Take a look at: http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/viewer.htm#a001071968.htm

Respected Advisor
Posts: 3,156

Re: Name of previous dataset

Posted in reply to JasonDiVirgilio

sysdsn

Haikuo

Super Contributor
Posts: 1,636

Re: Name of previous dataset

Posted in reply to JasonDiVirgilio

data class;


set sashelp.class;

proc print data=&syslast;


title from dataset &syslast;

run;

Contributor
Posts: 46

Re: Name of previous dataset

Thanks everyone...sysdsn and syslast both work great...they even include the libname used.

Interestingly, &syslast uses the format "libname.datasetname"

...where &sysdsn uses the format "libname    datasetname"


Valued Guide
Posts: 2,177

Re: Name of previous dataset

Posted in reply to JasonDiVirgilio

HI Jason

One wish remains unfulfilled. To have a convenient subtitle reporting the data set used in the reporting procedure we still need to submit that subtitle statement.

I would quite like have a feature that resolves when the procedure executes and not just when the title(n) or footnote statement is submitted.

footnote3 "reporting from #latest_ds" ;

I chose the # prefix because something like this used #byVal

just thinking

Respected Advisor
Posts: 3,799

Re: Name of previous dataset

Do you remember the super-duper PROC QPRINT.  It had options to include DSName and or DSLabel in the output

Valued Guide
Posts: 2,177

Re: Name of previous dataset

Posted in reply to data_null__

vaguely I recall qprint not providing what I needed (at the time) and proc print, did so I restricted that bit of learning (sounds like the well prepared excuse it is).

However didn't qprint become fsprint? forerunner of fsview and fsreport (now proc report)?

there is an excellent certification proposed by ChrisH in his SASDummy blog back at the beginning of this month for which I do not wish to qualify!

;-)

;-)

Respected Advisor
Posts: 3,799

Re: Name of previous dataset

Peter.C wrote:

vaguely I recall qprint not providing what I needed (at the time) and proc print, did so I restricted that bit of learning (sounds like the well prepared excuse it is).

It is quite possible that QPRINT did not provided what you needed at the time.  I wouldn't know anything about that.

However didn't qprint become fsprint? forerunner of fsview and fsreport (now proc report)?

No.

Respected Advisor
Posts: 4,925

Re: Name of previous dataset

Posted in reply to JasonDiVirgilio

data test;
x=1;
run;

title "Created &SYSLAST";

proc print; run;

PG

PG
🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 9 replies
  • 1872 views
  • 6 likes
  • 7 in conversation