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

I am currently using a code to break down one data-set multiple ones based on a Month variable.

 

Data _null_;
set work.unique_month;
call execute('data ' !! Compress(Month) !! ';set work.monthly_flags; where Month  = " ' !! Month !! ' "; run;'
run;

I would like to out put all the outputs to a permanent library. But the _null_ being the important aspect of the above code is writing the data to work library. Is there a way to write the datasets to a different library??

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

@shasank wrote:

I am currently using a code to break down one data-set multiple ones based on a Month variable.

 

Data _null_;
set work.unique_month;
call execute('data ' !! Compress(Month) !! ';set work.monthly_flags; where Month  = " ' !! Month !! ' "; run;'
run;

I would like to out put all the outputs to a permanent library. But the _null_ being the important aspect of the above code is writing the data to work library. Is there a way to write the datasets to a different library??


call execute('data perm.' !! Compress(Month) !! ';set work.monthly_flags; where Month  = " ' !! Month !! ' "; run;');

assuming PERM has been defined as a library name. By the way I have not checked the syntax of your CALL EXECUTE, because I don't think using CALL EXECUTE like this is a good thing to do.

 

As always, I point out that in general, it is a poor idea to split up a large data set into many smaller ones by calendar or other criterion, as whatever analysis you are going to do becomes much more cumbersome and inefficient to program and to execute. If you leave the results in one large data set, you can do analysis BY MONTH, for example, which is much easier to program, and much more efficient to run.

 

So in other words, DON'T DO what you are planning to do. Use one large data set and BY GROUP processing.

--
Paige Miller

View solution in original post

3 REPLIES 3
PaigeMiller
Diamond | Level 26

@shasank wrote:

I am currently using a code to break down one data-set multiple ones based on a Month variable.

 

Data _null_;
set work.unique_month;
call execute('data ' !! Compress(Month) !! ';set work.monthly_flags; where Month  = " ' !! Month !! ' "; run;'
run;

I would like to out put all the outputs to a permanent library. But the _null_ being the important aspect of the above code is writing the data to work library. Is there a way to write the datasets to a different library??


call execute('data perm.' !! Compress(Month) !! ';set work.monthly_flags; where Month  = " ' !! Month !! ' "; run;');

assuming PERM has been defined as a library name. By the way I have not checked the syntax of your CALL EXECUTE, because I don't think using CALL EXECUTE like this is a good thing to do.

 

As always, I point out that in general, it is a poor idea to split up a large data set into many smaller ones by calendar or other criterion, as whatever analysis you are going to do becomes much more cumbersome and inefficient to program and to execute. If you leave the results in one large data set, you can do analysis BY MONTH, for example, which is much easier to program, and much more efficient to run.

 

So in other words, DON'T DO what you are planning to do. Use one large data set and BY GROUP processing.

--
Paige Miller
shasank
Quartz | Level 8
Hi Paige, Thank you very much for the quick reply. I will make note of your suggestion and inform the same to the concerned.
ballardw
Super User

If you have actual dates, not just a month value you might consider using date values and Formats to create summary groups for reporting as well.

If you only have a month and year you might consider creating a date with a default day of the month such as the first. The date values can be manipulated a bit nicer than multiple variables as well as the flexibility of formats.

Consider the example below which creates 3 different types of summaries from a single date value. Through it the WEEK format and the custom formats that you can make this becomes very powerful. And if a format can't quite get the group you want the INTNX function can create things like biweekly values or quarters that start at different months than the typical calendar quarter, just to name a couple.

 

data example;
   /* this data set creates a random value
      for each calendar day from 1Jan2019 to 
      13Mar2020
   */
   do date= '01JAN2019'd to '13MAR2020'd;
      value = 100*rand('uniform');
      output;
   end;
   format date date9.;
run;

proc tabulate data=example;
   Title 'Summary from date value to year/month' ;
   class date;
   format date yymon.;
   var value;
   table date,
         value*(n mean max min std)
   ;
run;

proc tabulate data=example;
   Title 'Summary from date value to year/quarter';
   class date;
   format date yyq.;
   var value;
   table date,
         value*(n mean max min std)
   ;
run;

proc tabulate data=example;
   Title 'Summary from date value to month combining years';
   class date;
   format date monname.;
   var value;
   table date,
         value*(n mean max min std)
   ;
run;title;


SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 775 views
  • 3 likes
  • 3 in conversation