I produced the dataset b_monthly with date1, which is a date varaible
LN_NO | TPR_DATA_AS_OF_DT | Month | YEARMONTH_KEY | date1 |
0000000000 | 31Dec2014 | 201412 | 201412 | 201412 |
0000000000 | 29Nov2014 | 201411 | 201411 | 201411 |
0000000000 | 31Oct2014 | 201410 | 201410 | 201410 |
0000000000 | 30Sep2014 | 201409 | 201409 | 201409 |
0000000000 | 30Aug2014 | 201408 | 201408 | 201408 |
0000000000 | 31Jul2014 | 201407 | 201407 | 201407 |
Date1 is a date variable. I tried the following to segment it into separate datasets
%Macro dmart (date1);
data d_Monthly_&date1.;
set b_monthly;
run;
%Mend;
I ran the code but nothing was produced. I want to produce separate datasets such as
d_monthly_201412
d_monthly_201411
Here's a start:
data dateat;
infile cards;
informat ln_no $10. TPR_DATA_AS_OF_DT date9. Month YEARMONTH_KEY yymmn6.;
format ln_no $10. TPR_DATA_AS_OF_DT date9. Month YEARMONTH_KEY yymmn6.;
input LN_NO$ TPR_DATA_AS_OF_DT Month YEARMONTH_KEY date1;
cards;
0000000000 31Dec2014 201412 201412 201412
0000000000 29Nov2014 201411 201411 201411
0000000000 31Oct2014 201410 201410 201410
0000000000 30Sep2014 201409 201409 201409
0000000000 30Aug2014 201408 201408 201408
0000000000 31Jul2014 201407 201407 201407
;
run;
%macro date1;
%do i = 201412 %to 201407 %by -1;
data d_monthly_&i;
set dateat;
where date1 = &i;
run;
%end;
%mend;
%date1;
%Macro dmart (date1);
data d_Monthly_&date1.;
set b_monthly;
if &date1=date1 then output;
run;
%Mend;
Hi
Have a look at this blog post http://blogs.sas.com/content/sasdummy/2012/03/20/sas-program-by-processing/ by Chris Hemedinger
It shows very nicely on how to approach this. It will show how to find unique values for a given variable and then have a loop for each value and run some code. Since you already have char variables that are the value for spliting up the data sets I would use either Month or YEARMONTH_KEY
Bruno
Seems a fair bit of code to do (assuming the date field is distinct per the example, otherwise further below) what with all those macro variables, and index through it. Just use standard datastep with a call execute?:
data _null_;
set have;
call execute(cats('data want_',date,'; set have; run;'));
run;
And if its not the distinct list, just add:
proc sql;
create table LOOP as
select distinct DATE
from HAVE;
quit;
data _null_;
set loop;
call execute...;
run;
If the start and end dates are not known then you can try this
proc sql;
create table dates as select distint date1 as dates from b_monthly;
quit;
data _null_;
set dates;
call execute('data d_monthly_'||strip(dates)||';set b_monthly(where date1 = '||strip(dates)||');run');
run;
this is a FAQ
Here is a category with several answers.
http://www.sascommunity.org/wiki/Category:Making_subsets
short answers:
* do not split a data set
* Why? How about by processing?
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.