BookmarkSubscribeRSS Feed
AmitKB
Fluorite | Level 6
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
3 REPLIES 3
DanielSantos
Barite | Level 11
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.
DanielSantos
Barite | Level 11
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.
ChrisNZ
Tourmaline | Level 20
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.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 2515 views
  • 0 likes
  • 3 in conversation