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;
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.
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.