Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Output datasets based upon multiple dimensions

Status
Not open for further replies.

Medvedeff

Instructor
Feb 12, 2008
29
0
0
US
I am having a hard time trying how to code a macro to write out datasets based upon two variabiles, bucket and vintage;

My dataset looks like this:

input X Bucket Vintage;
10 1 1
20 1 1
30 1 2
40 1 2
50 1 3
60 1 3
70 2 1
80 2 1
90 2 2
100 2 2
110 2 3
120 2 3
;

I want to write out datasets in the format:

bucket_1_vintage_1
bucket_1_vintage_2
bucket_1_vintage_3
bucket_2_vintage_1
bucket_2_vintage 2
bucket_2_vintage_3

Simply hardcoding everything is rather cumbersome, because the actual dataset has 25 vintages, 10 buckets, and 10 variables. Simply replacing everything with a couple of macro lines would be greatly preferred.

Thanks in advance for your help!
 
Hi Medvedeff,
I'm on my way out to a meeting, but this might help you a little...
Code:
* Use array to create list of macro variables agnt1, agnt2 etc *;
*  each one contains an agent number                           *;
data _null_;
  set agents nobs=num_agents end=eof;
  file print;
  array agnt{99} $2;
  retain agnt;

  agnt{_n_} = agent;
  if eof then do;
    call symput('agnt_cnt',num_agents);
    do i = 1 to num_agents;
      rec = compress('agnt' || i);
      call symput(rec,agnt{i});
    end;
  end;
run;
Basically it loops through the records in a dataset and outputs each value of a sepcific variable into a sequentially numbered macro variable.
You should be able to use these in a do loop to then build your code.
If I get a chance this afternoon I'll check in again and see if I can put it together for you.
Chris.

Chris
Business Analyst, Code Monkey, Data Wrangler.
SAS Guru.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top