DATA Step, Macro, Functions and more

output a dataset with a dynamic name rather than staic name

Reply
SAS Employee kwu
SAS Employee
Posts: 34

output a dataset with a dynamic name rather than staic name

I am trying to partition a input table and only want to go through the input table only once and based on the partition key to output to the table.
I wonder if it is possible to output obs to a dynamic dataset name.

what I plan to do is to sort the input dataset by the partition key variable, then output to a new dataset when a new partitionkey is detected. however, I could not find a way to specify a output dataset name dynamically.

any suggestion would be appreciated.
Respected Advisor
Posts: 4,173

Re: output a dataset with a dynamic name rather than staic name

Hi
I would say this can't be done with one pass through the data as the output data sets are defined during compilation time but you only know how many and which names of data sets you need during execution time.

A possible approach would be to add a data _null_ step creating the SAS syntax you need, write this syntax to a temporay file and then %include this file after the data _null_ step to get it executed.

HTH
Patrick
Super Contributor
Super Contributor
Posts: 3,174

Re: output a dataset with a dynamic name rather than staic name

Using the DATA step and HASH technique, you have the OUTPUT() method that can dynamically create SAS files.

Scott Barry
SBBWorks, Inc.

Suggested Google advanced search argument, this topic / post:
hash output method documentation site:sas.com
Respected Advisor
Posts: 4,173

Re: output a dataset with a dynamic name rather than staic name

Beautyful!
I didn't realise this possibility of hash object usage so far.

Thanks a lot, Scott!
Respected Advisor
Posts: 3,799

Re: output a dataset with a dynamic name rather than staic name

This paper addresses the topic.

http://analytics.ncsu.edu/sesug/2008/SBC-119.pdf
SAS Employee kwu
SAS Employee
Posts: 34

Re: output a dataset with a dynamic name rather than staic name

Posted in reply to data_null__
Your guys are rock!!!
Thank you all very much indeed.
Ask a Question
Discussion stats
  • 5 replies
  • 1113 views
  • 0 likes
  • 4 in conversation