BookmarkSubscribeRSS Feed
sss
Fluorite | Level 6 sss
Fluorite | Level 6
ORG SITE LOC ASSET amount
===================================================
QUANTUM MCA MCA01 TRAN TRAN_HTT 310.00
QUANTUM MCA MCA01 TRAN TRAN_HTT 261.50
QUANTUM MCA MCA01 TRAN TRAN_HTT 273.80
QUANTUM MCA MCA01 TRAN TRAN_HTT 329.30
QUANTUM MCA MCA01 TRAN TRAN_HTT 290.80
QUANTUM MCA MCA01 TRAN TRAN_HTT 324.20
QUANTUM MCA MCA01 TRAN TRAN_HTT 346.30
IESI ATX ATX01 CNC_MIL_400 MIL_LIN_360 322.30
IESI ATX ATX01 CNC_MIL_400 MIL_LIN_360 320.30
IESI ATX ATX01 CNC_MIL_400 MIL_LIN_360 230.00
IESI ATX ATX01 CNC_MIL_400 MIL_LIN_360 367.00
IESI ATX ATX01 CNC_MIL_400 MIL_LIN_360 245.00
IESI ATX ATX01 CNC_MIL_400 MIL_LIN_360 225.00
IESI ATX ATX01 CNC_MIL_400 MIL_LIN_360 398.00
IESI ATX ATX01 CNC_MIL_400 MIL_LIN_360 401.00
IESI ATX ATX01 CNC_MIL_400 MIL_LIN_360 378.00
IESI ATX ATX01 CNC_MIL_400 MIL_LIN_360 265.00
IESI ATX ATX01 CNC_MIL_400 MIL_LIN_360 279.00
IESI ATX ATX01 CNC_MIL_400 MIL_LIN_360 376.00
IESI ATX ATX01 CNC_MIL_400 MIL_LIN_360 345.00
IESI ATX ATX01 CNC_MIL_400 MIL_LIN_360 256.00
IESI ATX ATX01 CNC_MIL_400 MIL_LIN_360 200.00
IESI ATX ATX01 CNC_MIL_400 MIL_LIN_360 278.00
IESI ATX ATX01 CNC_MIL_400 MIL_LIN_360 345.00
===============================================

i m having 25 obs i want to copy each obs in a new dataset.

Which means 25 obs should be split into 25 dataset . Each dataset consisting on 1 obs .

i can do in simple way like:
data one two three -------- twnyfive;
set datsetname;
run;

but my issue is that if there are 500 obs if i want 2 copy the values in 500 diffrent dataset i can write all 500 dataset name.

thnxzzzzz in advnce 🙂
6 REPLIES 6
MaxW
Calcite | Level 5
You could write a macro to do this:
First, get the number of obs into a macro var using a null data step or Proc SQL.
Then you could write a data step something like this:

data %do i=1 %to &N_obs; NewData&i %end;;
set OldData;
%do i=1 %to &N_obs;
if _N_=&i then output NewData&i;
%end;
run;
Reeza
Super User
Here's a macro solution, but I do wonder why you want to do this.

proc sql noprint;
select count(*) into :num_records from sashelp.class ;
quit;

%put &num_records;


%macro output_separate();

%do i=1 %to &num_records;
data data_&i;
format obsnum 8.;
obsnum=&i.;
set sashelp.class point=obsnum;
output;
stop;
run;
%end;
%mend;

%output_separate
sss
Fluorite | Level 6 sss
Fluorite | Level 6
HI Reeza

thnxs a lot its working f9
sss
Fluorite | Level 6 sss
Fluorite | Level 6
hi polingjw

Code is working gr8 thnx uuu
polingjw
Quartz | Level 8
You could also use a hash solution. Here is an example with sashelp.class.

[pre]

data _null_;
if _n_=1 then do;
declare hash h();
h.definekey('_n_');
h.definedata("Name", "Sex", "Age");
h.definedone();
end;
set sashelp.class;
h.clear();
h.add();
num = 'Obs'!!trim(left(put(_n_, 8.)));
h.output(dataset:num);
run;

[/pre]
SPR
Quartz | Level 8 SPR
Quartz | Level 8
Hello SSS,

This is a pure datastep solution:

[pre]data d1 d2 d3 d4;
set datsetname;
if _n_=1 then output d1;
else if _n_=2 then output d2;
else if _n_=3 then output d3;
else if _n_=4 then output d4;
run;
[/pre]
Sincerely,
SPR

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 6 replies
  • 821 views
  • 0 likes
  • 5 in conversation