Hi Guys
i have sas help library like sas help.class in this data sets 19 observation is there how to create 19 observation in 19 data sets
Advance Thanks
This works:
proc sql noprint;
select count(*)
into :NUMBEROBS
from sashelp.cars;
quit;
data %MACRO TABLES; /* create the tables */
%do i = 1 %to &NUMBEROBS;
work.OBS&i
%end;
%mend;
%tables;
set sashelp.cars;
%MACRO TESTS; /* assign the obs to each table */
%do i = 1 %to &NUMBEROBS;
if _N_ = &i then
output work.obs&i;
%end;
%mend;
%Tests;
run;
What for? You can always use the original dataset.
Sorry, its not clear what you mean. Do you want 19 copies of the same dataset, or 19 datasets with one record in each? Either way it really does not sound like th ebest way to go about doing whatever it is you want to do. SAS has inbuilt by group processing, so printing data by a variable and doing sums by a variable is far simpler using that.
for exp;
data ds1;
set sas help.class;
run;
in this data set we have 19 observation and 5 variable
i need 19 observation in 19 data set name ds1 ds19 like that
Thanks advance
Since these are just copies of the original, this is a useless waste of time. Use your mind for something that makes sense.
that the reason iam asking this the interview questions
Its possible, you could just put all the dsX on the data line, or you could be more complicated with:
data _null_;
set sashelp.vtable (where=(libname="SASHELP" and memname="CLASS")); do i=1 to nobs; call execute(cats('data ds',put(i,best.),'; set sashelp.class; run;')); end; run;
At the end of the day its pointless and a question like that would put me off the role.
** Updated to be dynamic with number of observations.
Or depending on what OP wants:
data _null_;
set sashelp.class;
call execute(catt('data ds',_N_,'; set sashelp.class(firstobs=',_N_,' obs= ',_N_,'); run;'));
run;
@bismilla wrote:
that the reason iam asking this the interview questions
If I put such a question into a interview questionnaire, I would only accept candidates that answer "I don't do it, it's useless".
@bismilla wrote:
for exp;
data ds1;
set sas help.class;
run;
in this data set we have 19 observation and 5 variable
i need 19 observation in 19 data set name ds1 ds19 like that
Thanks advance
Actually that code will generate errors as the LIBRARY name is one word: SASHELP not "SAS HELP". Your code would be asking to combine a data set name SAS in the default library, most likely WORK with a set named CLASS in a likely undefined library named HELP. Spelling really does count when it comes to programming.
See this log:
1 data ds1; 2 set sas help.class; ERROR: File WORK.SAS.DATA does not exist. ERROR: Libref HELP is not assigned. 3 run;
Which also demonstrates the use of the code box opened using the forum's {I} icon. It is better to post code and log entries into the code box as the forum main windows will reformat code and place additional characters that will sometimes prevent code from running when copied from the window.
This works:
proc sql noprint;
select count(*)
into :NUMBEROBS
from sashelp.cars;
quit;
data %MACRO TABLES; /* create the tables */
%do i = 1 %to &NUMBEROBS;
work.OBS&i
%end;
%mend;
%tables;
set sashelp.cars;
%MACRO TESTS; /* assign the obs to each table */
%do i = 1 %to &NUMBEROBS;
if _N_ = &i then
output work.obs&i;
%end;
%mend;
%Tests;
run;
Thank you so much thanks for your supporting
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.