BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
bismilla
Calcite | Level 5

 

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

1 ACCEPTED SOLUTION

Accepted Solutions
VRKiwi
Obsidian | Level 7

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; 

 

View solution in original post

11 REPLIES 11
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

bismilla
Calcite | Level 5

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

bismilla
Calcite | Level 5

that the reason iam asking this the interview questions

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

VRKiwi
Obsidian | Level 7

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;

 

Kurt_Bremser
Super User

@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".

ballardw
Super User

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

VRKiwi
Obsidian | Level 7

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; 

 

bismilla
Calcite | Level 5

Thank you so much thanks for your supporting

 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 11 replies
  • 1254 views
  • 1 like
  • 5 in conversation