Help using Base SAS procedures

Macro is doing nothing

Reply
Regular Contributor
Posts: 161

Macro is doing nothing

I took the do out but now it is doing nothing. can you help me figure out why.

Thanks for any help


%MACRO CreateMplusInput(filesave, filename, saslibname, Qname, dataname, IDname, itemstem, itemlist, numitem, ordervar, maxitemorder, attstem, attcat, numatt,
numclass, structon, structorder, loosen, processors);

options mprint mlogic symbolgen;
%let num_reps=1;

%let num_skills=5;
%let datafile=dat&seed.;
%let numitem=%eval(2**&num_skills-1);
%let numclass=%eval(2**&num_skills);
%let num_students=100;
%let IDname=num_student;

* CHANGED Import original data into work library, save as .dat file for Mplus;

data _NULL_;
set sas_cdm.student&seed;
file "C:\CDM\&datafile..dat";
put student_num Combinations question1-question&num_item ;
RUN;

******************************************************************************
********** Data Manipulation: ********
********** Getting Q Matrix and Attribute Patterns ********
******************************************************************************;
*CHANGED Import original Q_MATRIX into work library;
*****************************CHANGE ALL 3 TO &NUM_SKILLS****************;
DATA Qmatrix;
set sas_cdm.Q_Matrix;
* Renaming attributes to common format;
array skills{3} skills1-skills3;
ARRAY new(3) itematt1-itematt3;
DO i=1 TO 3; new(i)=skills(i); END;
item= _N_;
DROP i skills1-skills3;
run;

**************************END OF CHANGE ALL 3 TO &NUM_SKILLS**********;
*********************************************************************************
*Saving model order per item as macro variables;
*********************************************************************************;
***************CHANGE ALL 7 TO &NUMITEM*****************;
%MACRO SaveItemOrder;
%let ordervar=3;
DATA _NULL_;
/* Datasets to draw values from*/
%LET dataQmatrix=%SYSFUNC(OPEN(work.Qmatrix,i));
%DO i=1 %TO 7;
/* Assign new macro variables as global*/
%GLOBAL itemorder&i;
/* Gets entire row of data*/
%LET row=%SYSFUNC(FETCHOBS(&dataQmatrix,&i));
/* Grabs specific value for threshold from that row*/
%LET item&i.=%SYSFUNC(GETVARN(&dataQmatrix.,
%SYSFUNC(VARNUM(&dataQmatrix.,&ordervar.))));
/* Transferring value to global macro, and checking via log;*/
%LET itemorder&i. = &&item&i.;
%PUT itemorder&i. &&itemorder&i.;
%END;
/* Close dataset used in program;*/
%LET dataQmatrix=%SYSFUNC(CLOSE(&dataQmatrix.));
RUN;
%MEND;
%SaveItemOrder;

***************END OF CHANGE ALL 7 TO &NUMITEM*****************;
*********************************FIX OR CHANGE LATER**************;
/**** Steps in creating a class to pattern table:
* MACRO Classpattern:
* Creates an initial pattern of as many 0s and 1s in a row as needed
* Copies that pattern into separate datasets as needed
* Concatentates (then deletes) the separate datasets
* Result is one dataset per attribute with enough rows for all classes
* MACRO MergeIt:
* Merges (then deletes) datasets from each attribute together; */

%MACRO ClassPattern;
%global numatt;
%LET divisor=2;
%LET repeat = 1;
%LET numclass= 8; /*TAKE OUT; */
%LET totclass = &numclass.;

/*____________________________GET %LET NUMITEM= 7 OUT_______________________________ */
%LET NUMITEM= 7;
%LET numatt = 3;
%DO a=1 %TO &numatt.;
%DO r=1 %TO %EVAL(&repeat.);
DATA att&a.&r.;
DO c=1 TO &totclass.;
IF c LE (&totclass./&divisor.) THEN classatt&a.=0; ELSE classatt&a.=1;
OUTPUT;
END; DROP c;
run;
%LET repeat = %EVAL(&repeat.+1);
%END;
%IF &a.=1 %THEN %LET order = 1; %ELSE %LET order=%EVAL(&order.*2);
DATA att&a.; SET %DO loop=1 %TO &order.; Att&a.&loop. %END; ; run;
PROC DATASETS LIB=WORK NOLIST; DELETE %DO loop=1 %TO &order.; Att&a.&loop. %END; ;
RUN; QUIT;
%LET totclass = %EVAL(&totclass./2);
%END;
%MEND ClassPattern;
%ClassPattern;


%MACRO MergeIt;
DATA classpattern; RETAIN class; MERGE
%DO a=1 %TO &numatt.; Att&a. %END; ;
class = _N_; RUN;
PROC DATASETS LIB=WORK NOLIST; DELETE %DO a=1 %TO &numatt.; Att&a. %END; ;
RUN; QUIT;
%MEND;
%MergeIt;

/***********************ABOVE MIGHT NOT HAVE TO DO;**************************/

/***********************CHANGE 8 TO &numclass. AND 7 TO &numitem.************/
/* Creating item*attribute kernal table from classpattern matrix and Q matrix*/
/* Result is one row per class per item*/
DATA kernel;
DO class=1 TO 8;
DO item=1 TO 7;
class=class; item=item; OUTPUT;
END;
END;
RUN;
******************END OF CHANGE 8 TO &numclass. AND 7 TO &numitem.********************;
DATA kernel; MERGE kernel classpattern; BY class; RUN;
PROC SORT DATA=kernel; BY item class; RUN;
DATA kernel; MERGE kernel Qmatrix; BY item; RUN;

* Scoring by class and item to create kernel threshold values;
* Result is set of variables called "scoreatt" to be activated
if the item requires the attribute AND the class has it;
DATA kernel; SET kernel;
ARRAY aclass(&numatt.) classatt1-classatt&numatt.;
ARRAY aitem(&numatt.) itematt1-itematt&numatt.;
ARRAY ascore(&numatt.) scoreatt1-scoreatt&numatt.;
DO i=1 TO &numatt.;
IF aclass(i)=1 AND aitem(i)=1 THEN ascore(i)=1; ELSE ascore(i)=0;
END; DROP i;
RUN;
* Creating single variables that hold the "scoreatt" and attribute patterns;
DATA kernel; LENGTH scorepattern $10 attpattern $&numatt.; SET kernel;
scorepattern = CAT(OF item scoreatt1-scoreatt&numatt.);
attpattern = CAT(OF scoreatt1-scoreatt&numatt.);
RUN;
PROC SORT DATA=kernel; BY item scorepattern; RUN;
* Creates count variable for whether each "scoreatt" is unique
to an item to create a new threshold index as needed;
DATA kernel; SET kernel; BY item scorepattern; RETAIN thresh;
IF FIRST.Item THEN thresh=1;
IF scorepattern=LAG1(scorepattern) THEN thresh=thresh;
ELSE thresh=thresh+1;
RUN;
* The threshold count is one unit too high, so this FIXES it;
DATA kernel; RETAIN class item scorepattern thresh; SET kernel;
thresh=thresh-1;
RUN;
PROC SORT DATA=kernel; BY item class; RUN;
%mend;
%CreateMplus;
Super Contributor
Super Contributor
Posts: 3,174

Re: Macro is doing nothing

The SAS log would be much more useful than seeing the SAS program code.

Here's the OPTIONS statement you want to use to get the most diagnostic output:

OPTIONS SOURCE SOURCE2 MACROGEN SYMBOLGEN MPRINT /* MLOGIC */;

Scott Barry
SBBWorks, Inc.
Ask a Question
Discussion stats
  • 1 reply
  • 113 views
  • 0 likes
  • 2 in conversation