Hello,
I have been trying many options for building this Macro. Part of the problem is I do it once every 1 year or so hence my skills getting rusty. I want to pass in the “root” name of variables I have in my SPSS file then Concatenate them with the other parts to build up the full Variable name then add commas between the variables and put them in a “Mean” function. The number of variables can vary per macro call. Lets say I have 10 Brands called “BrandA” “BrandB” “BrandC” “BrandD” “BrandE” “BrandF” “BrandG” “BrandH” “BrandI” “BrandJ” and those are repeated for various “groups” of Brands like “Core” (Core_BrandA Core_BrandB… Core_BrandJ) “Own” (Own_BrandA Own_BrandB… Own_BrandJ) “Aware” (Aware_BrandA Aware_BrandB… Aware_BrandJ) Etc. My Code so far: DEFINE !Brand_avg (Mkt=!TOKENS(1) /NumBrand=!TOKENS(1) /Brnd1=!TOKENS(1) /Brnd2=!TOKENS(1) /Brnd3=!TOKENS(1) /Brnd4=!TOKENS(1) /Brnd5=!TOKENS(1) /Brnd6=!TOKENS(1) /Brnd7=!TOKENS(1) /Brnd8=!TOKENS(1) /Brnd9=!TOKENS(1) /Brnd10=!TOKENS(1)) Do if Market = !Mkt. COMPUTE Core_avg=MEAN( !DO !i=1 !TO !NumBrand !Concat('Core_',"Brnd",!i,",") !DOEND End If. EXECUTE. !ENDDEFINE. */////////////////////. SET MPRINT=YES MEXPAND = YES. !Brand_avg Mkt=1 NumBrand=5 Brnd1=BrandA Brnd2=BrandB Brnd3=BrandC Brnd4=BrandD Brnd5=BrandE Brnd6= Brnd7= Brnd8= Brnd9= Brnd10= . !Brand_avg Mkt=2 NumBrand=4 Brnd1=BrandA Brnd2=BrandC Brnd3=BrandD Brnd4=BrandH Brnd5= Brnd6= Brnd7= Brnd8= Brnd9= Brnd10= . !Brand_avg Mkt=3 NumBrand=6 Brnd1=BrandG Brnd2=BrandH Brnd3=BrandA Brnd4=BrandB Brnd5=BrandI Brnd6=BrandJ Brnd7= Brnd8= Brnd9= Brnd10= . DATA LIST LIST /Market Core_BrandA Core_BrandB Core_BrandC Core_BrandD Core_BrandE Core_BrandF Core_BrandG Core_BrandH Core_BrandI Core_BrandJ. BEGIN DATA 1 1 2 3 4 5 1 2 3 4 5 2 1 . 3 . 5 1 . 3 . 5 3 . 2 . 4 . 1 2 3 4 5 END DATA. LIST. **** Code I want generated:. Do if Market=1. COMPUTE Core_avg=MEAN(Core_BrandA,Core_BrandB,Core_BrandC,Core_BrandD,Core_BrandE). END IF. Do if Market=2 COMPUTE Core_avg=MEAN(Core_BrandA,Core_BrandC,Core_BrandD,Core_BrandH). END IF. Do if Market=3 COMPUTE Core_avg=MEAN(Core_BrandG,Core_BrandH,Core_BrandA,Core_BrandB,Core_BrandI,Core_BrandJ). END IF. Thanks for the pointers and help! ~Kevin. -- Sent from: http://spssx-discussion.1045642.n5.nabble.com/ ===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD |
Free forum by Nabble | Edit this page |