BookmarkSubscribeRSS Feed
Mscarboncopy
Pyrite | Level 9

 

When I work with macro to create sub scales, I normally list the total number of items and then use that number to calculate the missing.

For example, I am creating a scale X with sub scales A B and C

 

 

%macro ScaleX ; 

 

numitemsA = 10;

numitemsB = 3;

numitemsC = 5;

 

missA = nmiss (of I LIST EACH ITEM HERE);

miss B = nmiss (of I LIST EACH ITEM HERE);

missC = nmiss of I LIST EACH ITEM HERE);

 

if missA = numitemsA then subscaleA=.; ** all vars are missing;

            else   Sub scale A = (mean  (of I list the items again)\

I do the same for the other scales and it works perfectly.

 

However, in one of these sub scales, I have a different total item, depending on the group of participants (cohort). I will use sub scale A to try to explain.

 

Cohort 1 has only 5 of the 10 items of sub scale A (numitemsA) and cohort 2 has all 10 items (from numitemsA).

 

So I thought of doing

 

numitemsA = 10;

numitemsAA=5;

numitemsB = 3;

numitemsC = 5;

 

If cohort = 1 then missAA=nmiss (of list 5 items here);

If cohort = 2 then missA=nmiss (of list 10 items here);

 

 

if missA = numitemsA then subscaleA=.; ** all vars are missing;

            else  subScaleA= (mean (of list 10 items here));

if missAA =  numitemsAA then subScaleA=. ; ** all vars are missing;

            else subScaleA= (mean (of list 5 items here));

 

I also need to do this

if missA gt (.20*numitemsA) then subscaleA=.;

if missAA gt (.20*numitemsAA) then subscaleA=.;

%mend scaleX;

 

Would this overwrite the data? Or will I get the correct scaleA, calculated differently for each cohort, as shown above?

Thank you. 

1 REPLY 1
ballardw
Super User

Without some concrete data example I don't really have a clue what you are doing with "subscaling" or "scaling" here.

 

You might post some fake example data if sensitive, the parameters involved and the desired result for the given example data.

 

Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 1 reply
  • 264 views
  • 2 likes
  • 2 in conversation