BookmarkSubscribeRSS Feed
yifengwan
Calcite | Level 5

I am beginner user for SAS. Before I go to my questions, I really hope the person who answer can able to give me a clear guide to the problems as some books does not explain so clear.

1. do anyone have the experience in running SAS PROC MIXED, SAS PROC CALIS, SAS PRODCLIN, proc factor for multilevel data?

2. do anyone have a copy of macro language to analyze a multiple mediators in multilevel modeling?

3. may I know what is the proper steps in re-coding reversed variables Note; I do have several items that need to re-code.

Thanks in advanced.

3 REPLIES 3
Doc_Duke
Rhodochrosite | Level 12

At a certain level, your questions look like you are trying to do difficult things before you have learned how to do the simpler things.  You may need to first do the exercises in something like "The little SAS book" before starting on the main problem.

You should look at Littel, et al's book on MIXED and Hatcher's on SEM.  Both are readable, but assume you already know the basics of manipulating SAS.

To your third question, if the scales are numeric valued and ordinal or rational scaling, a simple way to reverse the scoring is to use

newscore = maxval - oldscore + minval;

where

oldscore is the existing scoring,

maxval is the maximum value for the scale, and

minval is the minimum value for the scale.

For instance, if the scale goes from 1-5 and you want to reverse it (so 4 becomes 2, etc.), then

new = 5 - old + 1;

Doc Muhlbaier

Duke

yifengwan
Calcite | Level 5

Thanks Duke,

first I apologized for the very late reply as I was busy reading up those books that you recommended me as you noted in your last reply. Yes, I grape some important points out of it.

Together with this reply, I have attached my project framework for your better understanding of my research. as we know in the process of data collection, we couldn't run away from missing data. Below is some of my research data and some proc which I am going to use to analyze my data.

****************************************************************************************************************************************************************************************************************************************************************************************

* LABEL

L5, L9, L11, L13  ='IDEALIZED ATTRIBUTES'

L2, L7, L12, L19  ='IDEALIZED BEHAVIOURS'

L4, L6, L14, L20  ='INSPIRATIONAL MOTIVATION'

L1, L3, L16, L18  ='INTERLECTUAL SIMULATION'

L8, L10, L15, L17 ='INDIVIDUALIZED CONSIDERATIONS'

OP24, OP25, OP33, OP34  ='RATUINAL GOAL'

OP27, OP31, OP32, OP36  ='OPEN SYSTEM'

OP21, OP23, OP26, OP29  ='INTERNAL PROCESS'

OP22, OP28, OP30, OP35  ='HUMAN RESOURCE'

JS37-JS56 ='JS'

AC57-AC62 ='AC'

OCB65, OCB80, OCB83, OCB84, OCB86  ='CONSCIENTIOUSNUESS'

OCB64, OCB66, OCB69, OCB78, OCB81  ='SPORTMENSHIP'

OCB68, OCB71, OCB73, OCB74         ='CIVIC VIRTUE'

OCB67, OCB70 OCB76, OCB79, OCB82   ='CERTESY'

OCB63, OCB72, OCB75, OCB77, OCB85  ='ATTRUISM';

DATA MDATA1;

INPUT #1 @1  (COID) (3.)

  @5  (LEADER) (1.)

  @7  (NONLEADER) (1.)

  @9  (SEX) (1.)

  @11  (AGE) (2.)

  @14  (RACE) (1.)

  @16  (MARITAL) (1.)

  @18  (TENURE) (3.)

  @22  (TENUREJOB) (3.)

  @26  (MONTHLYS) (5.)

  @32  (EDULVL) (1.)

  @34  (POSITION) ($20.)

  @55  (L1-L20) (1.) 

   #2 @1   (OP21-OP36) (1.) 

   #3 @1   (JS37-JS56) (1.)

    @22  (AC57-AC62) (1.)

  @29  (OCB63-OCB86) (1.);

CARDS;

614 1 0 2 37 1 1 36 003        4 Advertising Sale     44534454444433544444

5656565555454556

614 0 1 2 37 1 1 36 003        4 Advertising Sale     44535454345545444434

55545444543435354443 434435 434544544545454543543 43

614 0 1 1    2 1               4 Advertising      42442442344533443444

33433344434332443355 323234 415253142414443244241434

614 0 1 2 49 2 3 341 257 11000 2 Advertising          32343443443343232433

43443344535324443445 342225 315154155544444144154544

614 0 1 2 55 1 3 372 060 10000 4 Advertising  43443543423334333444

45434444444453444435 544124 324234132414414235232544

614 0 1 2 35 1 3 014 014 9000  4 Advertising  45444543444454444445

44544445544444444545 342214 425145143424554245154544

614 0 1 2 49 1 3 288 064   4 Advertising  43343443433444344444

44443444444334444334 442234 324224244444454345233444

614 0 1 1 54 3 3 432 012   3 Advertising  44443544444444343444

43334433343333333333 552225 425344344434443155223433

614 0 1 1 47 1 3 292 081   4 Advertising  23232232432422321233

44432343334333444334 332224 42524414 424444135245444

272 1 0 2 36 2 3 60  60        5 Audit  53541444433342443333

6534555556546564

272 0 1 1 31 2 1 25  25  4150  4 Accounts  44445543344444444443

44444444344444444344 431114 424244144344444444134444

272 0 1 2 48 2 3 272 53  7150  4 Estate  44445544444444444444

44444444444444444444 441114 415244144445354334144444

272 0 1 1 46 2 3 252 120 6180  4 Accounts Secretery   53543433534443444454

53444454444444444335 443224 43523414443443424534 133

793 1 0

793 0 1 2 27 2 1 7   7   2000  4 Corporate Planning   34443444434444444444

24444444444223444554 442224 434354345454313253245553

793 0 1 1    2 3 61  61  6000  4 Complience & Ledal   54444444444455544555

55555545555555555555 531115 414354141423444243343444

793 0 1 1 33 3 1 17  17        4 Finance  11123534114323222223

23222333332332333442 223333 134243453333313341233313

793 0 1 1 43 2 3     51  3500  3          33444444323333333333

33233333433332343333 342224 334143151344444333243433

793 0 1 1 34 2 3 108 72        4 Finance  53433444444544444444

34434443344443344444 442223 414144143434444243243333

(until it ended with (;) on the following line

DATA MDATA;

  SET MDATA1 MDATA2;

PROC PRINT Data=mdata (obs=10);

RUN;

*Creating New Data Set for Analysis;

DATA MDATA_NEW;

  SET MDATA;

*Recoding reversed Variables;

AC59 = 6 - AC59;

AC60 = 6 - AC60;

AC61 = 6 - AC61;

AC = (AC57 + AC58 + AC59 + AC60 + AC61 + AC62) / 6;

OCB64 = 6 - OCB64;

OCB66 = 6 - OCB66;

OCB69 = 6 - OCB69;

OCB78 = 6 - OCB78;

OCB81 = 6 - OCB81;

S = (OCB64 + OCB66 + OCB69 + OCB78 + OCB81) / 5;

*DATA MANIPULATION;

IA = (L5 + L9 + L11 + L13) / 4;

IB = (L2 + L7 + L12 + L19) / 4;

IM = (L4 + L6 + L14 + L20) / 4;

IS = (L1 + L3 + L16 + L18) / 4;

IC = (L8 + L10 + L15 + L17) / 4;

TFL = (IA + IB + IM + IS + IC) / 5;

RG = (OP24 + OP25 + OP33 + OP34) / 4;

OS = (OP27 + OP31 + OP32 + OP36) / 4;

IP = (OP21 + OP23 + OP26 + OP29) / 4;

HR = (OP22 + OP28 + OP30 + OP35) / 4;

OP = (RG + OS + IP + HR) / 4;

JS = (JS37 + JS38 + JS39 + JS40 + JS41 + JS42 + JS43 + JS44 + JS45 + JS46 +

  JS47 + JS48 + JS49 + JS50 + JS51 + JS52 + JS53 + JS54 + JS55 + JS56) / 20;

CONS = (OCB65 + OCB80 + OCB83 + OCB84 + OCB86) / 5;

CV = (OCB68 + OCB71 + OCB73 + OCB74) / 4;

C = (OCB67 + OCB70 + OCB76 + OCB79 + OCB82) / 5;

ATT = (OCB63 + OCB72 + OCB75 + OCB77 + OCB85) / 5;

OCB = (CONS + S + CV + C + ATT) / 5;

*Create Value Label for the Demographic Section;

PROC FORMAT;

  VALUE Sex 1 = "Female" 2 = "Male";

  VALUE Race 1 = "Chinese" 2 = "Malay" 3 = "Indian" 4 = "Others";

  VALUE Marital 1 = "Single" 2 = "Married" 3 = "Others";

  VALUE Edulvl 1 = "Primary" 2 = "Secondary" 3 = "Diploma" 4 = "Degree" 5 = "Master's" 6 = "Doctorate";

RUN;

OPTION NOCENTER NODATE NONUMBER NOLABEL;

DATA mdata_new2a;

  SET mdata_new;

  IF LEADER=1;

DATA mdata_new2b;

  SET mdata_new;

  IF NONLEADER=1;

/*****Descriptive Statistics for Level-2 Variables*****/

PROC MEAN DATA=mdata_new2a MEAN STD;

  VAR TFL OP;

RUN;

/*****Descriptive Statistics for Level-1 Variables*****/

PROC MEAN DATA=mdata_new2b NEAB STD;

  VAR TFL JS AC OCB;

RUN;

/*****MODEL 1*****/

TITLE "Unconditional Mean Model";

PROC MIXED DATA=mdata_new METHOD=ML COVTEST Noclprint;

  CLASS coid;

  MODEL OP = / Solution;

  RANDOM intercept / TYPE=UN Subject=coid;

RUN;

/*****MODEL 2*****/

Title "MODEL 2A: Including Effects of Transformational Leadership (LEVEL-2) Predictors";

PROC MIXED DATA=mdata_new2a METHOD=ML COVTEST Noclprint;

  CLASS coid;

  MODEL op = tfl / Solution DDFM = bw;

  RANDOM Intercept / TYPE=UN SUBJECT=coid;

  REPEATED / TYPE=VC SUBJECT=coid;

RUN;

/*comparing the degrees of freedom with and w/o option ddfm = bw*/

PROC MIXED DATA=mdata_new2a METHOD=ML COVTEST Noclprint;

  CLASS coid;

  MODEL op = tfl / solution ;

  RANDOM intercept / TYPE = UN subject = coid;

  REPEATED / TYPE=VC SUBJECT=coid;

run;

Title "MODEL 2b: Including Effects of Transformational Leadership (LEVEL-1) Predictors";

PROC MIXED DATA=mdata_new2b METHOD=ML COVTEST Noclprint noitprint;

  CLASS coid;

  MODEL op = tfl / Solution DDFM=bw Notest;

  RANDOM Intercept tfl / SUBJECT=coid TYPE=UN;

  REPEATED / TYPE=UN SUBJECT=coid;

RUN;

/*****MODEL 3*****/

Title "Model 3: Including Both Level-1 and Level-2 Predictors";

Title2 "--Predicting op from leader, momleader, tfl and";

Title3 "cross level interaction of  nonleader and tfl";

PROC MIXED DATA=mdata_new noclprint covtest noitprint;

  CLASS coid;

  MODEL op = leader nonleader tfl leader*tfl nonleader*tfl / Solution DDFM=bw Notest;

  RANDOM Intercept tfl / Subject=coid TYPE=UN;

RUN;

**********************************************************************************************************************************************************************************************************

if you notice, I had made it bold in some of the parts in the proc step and one of the datalines. The one which I bold in the dataline is a missing case. Meanwhile the proc step which I bold produce an error while I submit for process. would you mind help me to check out what It had been wrong and how can I include the level-1 data to be in the equation when I make a relationship with the outcome variable which is in Level-2

Another problem which I am having right now is how to conduct a diagnostics test on multilevel data with SAS MACRO_DX? do you know how to fit in the data into the macro to run the diagnostics test for multilevel modeling data?

Thank you very much.

Doc_Duke
Rhodochrosite | Level 12

HI,

I haven't used MIXED in quite a while, so I can't help you on the specifics.  If you post the section of your log with the error message, maybe someone else can help.

Doc Muhlbaier

Duke

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1441 views
  • 3 likes
  • 2 in conversation