X-Organization: from SUNY College at Oneonta, NY 13820
X-Envelope-to: sas-l@uga.BITNET
X-VMS-To: IN%"sas-l@uga"
X-VMS-Cc: STROTHHM
Newsgroups: bit.listserv.sas-l
Date:         Fri, 11 Sep 1992 13:45:00 EDT
Reply-To:     Helen Strother <STROTHHM@SNYONEVA.BITNET>
From:         Helen Strother <STROTHHM@SNYONEVA.BITNET>
Subject:      Re: Long macro variable

Hi all,
        Maybe I should explain why I need this long macro variable and if
someone has a more elegant solution, I would be extremely grateful.  For about
a month now, I have been working on a SAS macro that will serve as a front end
for students doing political analysis on an ICPR database which has already
been converted into a SAS data set.  The students can pick up to 10 variables,
recode variables and also create new variables, and then do frequencies and
crosstabulations on any combination of the above.  One capabilty that the
professor wanted the program to have is that when a student creates a new
variable, the program should give all the possible combinations of the
variables he or she is using to create the new variable.  What I decided to do
is to create another data set containing two variables - Var which references
the the variable in the ICPR data set and POSANS which is a string of all the
possible answers to that variable.  For example:

VAR     POSANS
0001    001002003004005
0002    001002003004005

The following data step creates a data set with all possible combinations of
the selected variables:

  data matrix(keep=resp1-resp&nci);
             length resp1-resp&nci 3;
             point=1;
             set tempft (rename=(posans=pa1))
               point=point;
             point=2;
             set tempft (rename=(posans=pa2))
                point=point;
             do i = 1 to length(pa1) by 3;
                do j = 1 to length(pa2) by 3;
                   resp1 = substr(pa1,i,3);
                   resp2 = substr(pa2,j,3);
                   output;
                end;
             end;
             stop;
             run;

This all works fine but I have come across some variables that have more
answers than will fit into a 200 byte character variable.  I am not adverse to
creating a different data set to handle the variables and the possible answers,
would something like this work better?

VAR     Posans
0001    001
0001    002
0001    003
0001    004
0001    005
0002    001
0002    002
0002    003
0002    004
0002    005

The reason why I went with the original structure of the data set is that I
didn't have to be concerned with how many possible answers there were.
Realize that some variables have 3 possible answers while others have more than
100.  How would I write the data step to create all possible combinations with
the data set structured this way?  Thanks.


                          Helen Strother STROTHHM@SNYONEVA

Regarding Kernon Gibe's comments on Bob Snyder's response to the looong
macro variable question, yes Bob's suggestion does work.  (See test below
run successfully under VM/CMS.)  According to the SAS Guide to Macro
Processing V5, Appendix 2, the max length of the macro variable is
controlled by the MWORK= system option with a default of 2k (2048 bytes)
and max value of 28k.  I agree with Bob, however, that there must be a
more elegant solution than concatenating a huge macro variable.
Regardless, his code works fine.

**** Test code ****
%let mvar = ;
Data temp;
  Input varnum $ possans $;
    Call Symput('mvar',Symget('mvar')||' '||compress(possans));
cards;
01 Jack
02 and
03 Jill
04 ran
05 up
06 the
07 hill
;
Run;

%put mvar = &mvar; run;

produces:  Jack and Jill ran up the hill

  ***** End code. *****

*NYS*DoT*CMS*IBM*3090-400*SAS*5.18*6.07*GRAPH*FSP*STAT*ANYSUG*

      Michael F. Perry           Using SAS 5&6 under CMS for:
 Assoc. Computer Prog/Analyst      Bid analysis (BAMS/DSS) &
  NYS Dept of Transportation       Project Estimating
   State Campus, Bldg 4-220                Planning &
      Albany, NY  12232                    Management.

*NYS*DoT*(518)*457*5259*PLANES*TRAINS*AUTOMOBILES*BOATS*BIKES*
Comments: Gated by NETNEWS@AUVM.AMERICAN.EDU