BookmarkSubscribeRSS Feed
Q1983
Lapis Lazuli | Level 10

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

6 REPLIES 6
Steelers_In_DC
Barite | Level 11

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;

slchen
Lapis Lazuli | Level 10

%Macro dmart (date1);

data d_Monthly_&date1.;

set b_monthly;

if &date1=date1 then output;

run;

%Mend;

BrunoMueller
SAS Super FREQ

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

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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;

MadhuKorni
Quartz | Level 8

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;

Ron_MacroMaven
Lapis Lazuli | Level 10

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?

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 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
  • 6 replies
  • 1288 views
  • 1 like
  • 7 in conversation