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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

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