BookmarkSubscribeRSS Feed
thanikondharish
Fluorite | Level 6
/*28jul*/
Data set name: ex_28

/*29jul*/
Data set name: ex_29

/*30jul*/
Data set name: ex_30
/*31jul*/
Data set name: ex_31

My query is how append every 3 days like
1st day:
Ex_28.

2nd day:
Append. Ex_28 Ex_29

3rd day:
Append Ex_28 Ex_29 Ex_30

4th day:
Append Ex_29 Ex_30 Ex_31
On 4th day we have to avoid first day data set
13 REPLIES 13
andreas_lds
Jade | Level 19

How are the datasets named after day 4?

Will the datasets, that aren't needed for appending any more, be deleted?

Is there a variable in the datasets to identify the day of creation/import?

 

It is almost always a bad idea to dates, years or such information in dataset names, processing data will be easier if such information is stored in variables.

thanikondharish
Fluorite | Level 6
Day 4:Ex_31
Day 5:Ex_1.........
thanikondharish
Fluorite | Level 6
If all are 31 days months
andreas_lds
Jade | Level 19

@thanikondharish wrote:
If all are 31 days months

Interesting concept ... you will have to give us some more examples, especially explaining what should happen when month changes.

 

ScottBass
Rhodochrosite | Level 12

Is there any way you can rename your datasets from this poorly designed naming convention to ex_yyyymmdd, for example ex_20190730, ex_20190731, ex_20190801, ...., ex_20200101, etc.?  It will make your life much easier.


Please post your question as a self-contained data step in the form of "have" (source) and "want" (desired results).
I won't contribute to your post if I can't cut-and-paste your syntactically correct code into SAS.
thanikondharish
Fluorite | Level 6
No problem datasets may like that also like you mentioned
Kurt_Bremser
Super User

Since you haven't been forthcoming with requested details, I can only give you code to compute the dataset names for three days past:

data _null_;
length ds_string $100;
do date = today() - 2 to today();
  ds_string = catx(' ',ds_string,'ex_' !! put(date,yymmddn8.));
end;
call symputx('ds_string',ds_string);
run;

data want;
set &ds_string.;
run;
thanikondharish
Fluorite | Level 6
Thanq it's working
ScottBass
Rhodochrosite | Level 12

Your original requirements:

My query is how append every 3 days like
1st day:
Ex_28.

2nd day:
Append. Ex_28 Ex_29

3rd day:
Append Ex_28 Ex_29 Ex_30

4th day:
Append Ex_29 Ex_30 Ex_31
On 4th day we have to avoid first day data set

 

The solution:

 

data _null_;
length ds_string $100;
do date = today() - 2 to today();
  ds_string = catx(' ',ds_string,'ex_' !! put(date,yymmddn8.));
end;
call symputx('ds_string',ds_string);
run;

data want;
set &ds_string.;
run;

Thanq it's working

 

How is this "working"?  Your requirements were to return one dataset on day 1, two datasets on day 2, 3 datasets on day 3, then a rolling 3 datasets backwards from day 4 onward.  The solution doesn't do that.  And you say that you only append every three days, not every day per the solution.

 

You need to learn to ask a better question if you expect a better answer (and in less than two pages and 13 posts).

 

 


Please post your question as a self-contained data step in the form of "have" (source) and "want" (desired results).
I won't contribute to your post if I can't cut-and-paste your syntactically correct code into SAS.
ScottBass
Rhodochrosite | Level 12

@thanikondharish wrote:



My query is how append every 3 days like
1st day:
Ex_28.

2nd day:
Append. Ex_28 Ex_29

3rd day:
Append Ex_28 Ex_29 Ex_30

4th day:
Append Ex_29 Ex_30 Ex_31
On 4th day we have to avoid first day data set

 

You say append.  Do you mean concatenate instead?  If you're appending, wouldn't you just append to the base table each day?  Or are you wanting a rolling three days?

 

I started with this, but I'm bailing out.  I don't know exactly what you want to do.

 

* create some dummy datasets ;
data dates;
   do date="01JUL2019"d to "31JUL2019"d;
      output;
   end;
   format date yymmddn8.;
run;

proc sql noprint;
   select date into :dates separated by " " from dates;
quit;

%macro code;
   data ex_&word;
      chr_date="&word";  * dummy data ;
   run;
%mend;
%loop(&dates)

* initialize audit log ;
data auditlog;
   length rundate startdate enddate 8;
   format rundate date9. startdate enddate yymmddn.;
   rundate     = today();
   startdate   = today();
   enddate     = today();
run;

proc sql;
   select
      intnx('day',max_enddate,1) as startdate format=yymmddn.
     ,intnx('day',max_enddate,3) as startdate format=yymmddn.
   into
      :startdate,:enddate
   from (
   select 
      max(enddate) as max_enddate
   from
      auditlog
   )
   ;
quit;

%put &=startdate &=enddate;

* loop over the dates, append the source tables, and write a row to the audit log. ;

You don't explain what logic determines 1st day, 2nd day, 3rd day.

 

Maybe you can run with this code and make something work.

 

At this point I'm guessing at the details of what you want to do, and why you want to do it.

 

Perhaps get a colleague to help you better ask your question?

 

See https://github.com/scottbass/SAS/blob/master/Macro/loop.sas for the %loop macro.


Please post your question as a self-contained data step in the form of "have" (source) and "want" (desired results).
I won't contribute to your post if I can't cut-and-paste your syntactically correct code into SAS.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 13 replies
  • 2738 views
  • 2 likes
  • 4 in conversation