BookmarkSubscribeRSS Feed
Rasheed
Calcite | Level 5

I have multiple data set and using following program I have split data according to variable Siml

data _null_;                                                                                                                                                                                                                                                   

     declare hash h();                                                                                                                                                                                                                                         

     h.definekey('_n_');                                                                                                                                                                                                                                       

     h.definedata('Siml', 'Subj', 'Seq', 'P','Reg', 'LogAuc', 'LogCmax');                                                                                                                                                                                      

     h.definedone();                                                                                                                                                                                                                                           

     do _n_=1 by 1 until (last.Siml);                                                                                                                                                                                                                          

           set analysis;                                                                                                                                                                                                                                       

           by Siml;                                                                                                                                                                                                                                            

           rc=h.replace();                                                                                                                                                                                                                                     

     end;                                                                                                                                                                                                                                                      

     rc=h.output(dataset:cats('want',Siml));                                                                                                                                                                                                                   

run;

Now I want to use these split data set in my further analysis for this I have written following macro code that is working fine but i want to do this without macro Plz help

%macro split;                                                                                                                                                                                                                                                  

data finall;                                                                                                                                                                                                                                                   

set                                                                                                                                                                                                                                                            

%do i = 1 %to 5;                                                                                                                                                                                                                                               

want&i;                                                                                                                                                                                                                                                        

run;                                                                                                                                                                                                                                                           

                                                                                                                                                                                                                                                               

proc print data=want&i;                                                                                                                                                                                                                                        

run;                                                                                                                                                                                                                                                           

                                                                                                                                                                                                                                                               

%end;                                                                                                                                                                                                                                                          

;                                                                                                                                                                                                                                                              

run;                                                                                                                                                                                                                                                           

                                                                                                                                                                                                                                                               

%mend;

6 REPLIES 6
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Lets jump back a moment here.  Start by posting an example (in the form of a datastep) and and example of what you want out.   I see no reason in the above code why you would be using hash code, nor why you would want to split data in the first place.  There is probably a very simple process for what you want to do, however I cannot see it from what you have posted.

Rasheed
Calcite | Level 5

Dear RW9

I have a data set in which there are some variables like Siml, Seq, P,,,,,,,,

Now I want to split this data set according to variable Siml for this I am using following code and its work fine

data _null_;

     declare hash h();

     h.definekey('_n_');

     h.definedata('Siml', 'Subj', 'Seq', 'P','Reg', 'LogAuc', 'LogCmax');

     h.definedone();

     do _n_=1 by 1 until (last.Siml);

           set complete;

           by Siml;

           rc=h.replace();

     end;

rc=h.output(dataset:cats('want',Siml));

run;

Now I want to use these split data set in my further analysis for this I have written following macro code that is working fine but i want to do this without macro Plz help


%macro split;

data finall;

set

%do i = 1 %to 5;

want&i;

run;

proc print data=want&i;

run;

%end;

;

run;

   %mend;


RW9
Diamond | Level 26 RW9
Diamond | Level 26

Yes, but you haven't answered the question.  Why do all that code to split a dataset - which in itself is not a recommended approach - when simpler code might make the data easier to use.  After splitting it then you just seem to be putting it back together again.  Just doesn't make sense.  If you don't want to use macro then:

data _null_;

     call execute('data final; set ');

     do i=1 to 5;

          call execute(' want'||strip(put(i,best.)));

     end;

     call execute('; run;');

run;

However it is really doing the same thing at the end of the day.

Also, if they are all called the same name then you can use the colon modifier:

data tmp1;

  a=1;

run;

data tmp2;

  a=2;

run;

data want;

  set tmp:;

run;

Rasheed
Calcite | Level 5

Thank you very much for your reply I tried your code and its working fine thank you again

There is thing that is bothering me if I want to print split data in ever do loop as I did in macro program so what command should I add in your first code of call execute

Regards

Rasheed
Calcite | Level 5

And is there any option by which I can print these split data sets using do loop?

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Well, yes:

data _null_;

     call execute('data final; set ');

     do i=1 to 5;

          call execute(' want'||strip(put(i,best.)));

     end;

     call execute('; run;  proc print data=want'||strip(put(i,best.))||'; run;');

run;

However, if the only reason you want to split them is to print them separately, then look at by group processing.  You just need one variable in your dataset, and then you can do:

proc print data=want;

     by id_var;

run;

And if you want further options move to proc report, then you can do page by, groupings, computed items etc.  That would be my suggestion.  It really looks like your coding all of this just to avoid using proc report which doesn't make sense as that is a very powerful reporting environment.

sas-innovate-2024.png

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.

 

Register now!

How to connect to databases in SAS Viya

Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 6 replies
  • 1242 views
  • 0 likes
  • 2 in conversation