Hi All,
My data looks like this
| Name | Contents |
| RE_OP | Sydney |
| RE_OP | Brussels |
| RE_OP | Paris |
| RE_TRF | Newyork |
| RE_TRF | Washington |
| RE_TRF | Houston |
| RE_TRF | Dayton |
And I want to create 2 multiple datasets of name
Data set RE_OP should contain
| Name | Contents |
| RE_OP | Sydney |
| RE_OP | Brussels |
| RE_OP | Paris |
and Dataset RE_TRF should contain
| Name | Contents |
| RE_TRF | Newyork |
| RE_TRF | Washington |
| RE_TRF | Houston |
| RE_TRF | Dayton |
So Basically, I want to create individual datasets of group , somehow I am unable to create it.
Any help is really appreciated
Thanks in advance
Hi,
Please try this. Hope this will help you.
data try;
infile datalines;
input name $ content $;
datalines;
RE_OP Sydney
RE_OP Brussels
RE_OP Paris
RE_TRF Newyork
RE_TRF Washington
RE_TRF Houston
RE_TRF Dayton
;
run;
proc sql noprint;
select distinct name into : x separated by ' ' from try;
quit;
%macro create;
%do i = 1 %to %eval(%sysfunc(count(&x, %str( )))+1);
data %scan(&x,&i.);
set try;
if name = "%scan(&x,&i.)";
run;
%end;
%mend;
%create
Br,Amit
A single datastep can produce many datasets :
data RE_OP RE_TRF;
set myData;
if Name = "RE_OP"
then output RE_OP;
else output RE_TRF;
run;
PG
Thanks PGStats , but i dont know if my datasets will always have 2 distinct groups only, how can I generalize then ?
This is a fairly common question, some of the solutions are outlined in the following link. Note the best practice - Don't do it.
The only time I've violated it, was doing a simulation and I didn't have enough disk space to store the simulated datasets.
Hi,
Please try this. Hope this will help you.
data try;
infile datalines;
input name $ content $;
datalines;
RE_OP Sydney
RE_OP Brussels
RE_OP Paris
RE_TRF Newyork
RE_TRF Washington
RE_TRF Houston
RE_TRF Dayton
;
run;
proc sql noprint;
select distinct name into : x separated by ' ' from try;
quit;
%macro create;
%do i = 1 %to %eval(%sysfunc(count(&x, %str( )))+1);
data %scan(&x,&i.);
set try;
if name = "%scan(&x,&i.)";
run;
%end;
%mend;
%create
Br,Amit
data Have;
input name $ contents $;
cards;
RE_OP Sydney
RE_OP Brussels
RE_OP Paris
RE_TRF Newyork
RE_TRF Washington
RE_TRF Houston
RE_TRF Dayton
;
proc sql;
create table Names as select distinct name from Have;
quit;
data _null_;
set Names;
call execute("data "||strip(name)||";set Have;where name = '"||strip(name)||"';run;");
run;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!
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.
Ready to level-up your skills? Choose your own adventure.