DATA Step, Macro, Functions and more

Automatic creation of datasets based on variable value

Reply
Frequent Contributor
Posts: 99

Automatic creation of datasets based on variable value

Hi all,
I want to create multiple datasets based on variable 'x' value.

The below example shows how to create the datasets using IFthen. But there are more than 200 disnict values of 'x' in the Real dataset, hence I need a more efficient way of doing it rather than specifying individual If Then.

data test1;
input x;
datalines;
2
3
2
1
2
1
3
;
run;

data out.temp1 out.temp2 out.temp3;
set test1;
if x eq 1 then output out.temp1;
if x eq 2 then output out.temp2;
if x eq 3 then output out.temp3;
run;


Thanks for your help,

Amit
Super Contributor
Posts: 474

Re: Automatic creation of datasets based on variable value

Hello Amit.

Easily achieved with the output method of the Hashing object.

See the "SPLITTING A SAS FILE DYNAMICALLY USING THE .OUTPUT() METHOD" topic of this excellent paper by Paul M. Dorfman and Koen Vyverman:
http://www2.sas.com/proceedings/sugi30/236-30.pdf

Cheers from Portugal.

Daniel Santos @ www.cgd.pt.
Super Contributor
Posts: 474

Re: Automatic creation of datasets based on variable value

Posted in reply to DanielSantos
Something I should add...

There is some limitation about the size (num. of colums X num. rows) that can be allocated into memory through the hash object.

Cheers from Portugal.

Daniel Santos @ www.cgd.pt.
PROC Star
Posts: 1,759

Re: Automatic creation of datasets based on variable value

Daniel's paper is very good indeed, and if there is too much data for the hash tables, you can look at the example just above the one he mentions.

Also, I would add
hid.delete ( );
just before the run; statement: use option fullstimer to see that memory usage should be reduced this way.
Ask a Question
Discussion stats
  • 3 replies
  • 521 views
  • 0 likes
  • 3 in conversation