dm "log; clear; odsresults; clear;"; options linesize=64 nonumber nodate; options mprint symbolgen mlogic; *********************************************************************; * AUTHOR: Chris Bilder *; * DATE: 7-8-16 *; * PURPOSE: macros with the cereal data set *; *********************************************************************; title1 "Chris Bilder, STAT 850"; *Read in the data set from a comma delimited file; proc import out=cereal datafile="C:\data\cereal.csv" DBMS=CSV replace; getnames=yes; datarow=2; run; *Adjust for serving size; data set1; set cereal; sugar = sugar_g/size_g; fat = fat_g/size_g; sodium = sodium_mg/size_g; *remove the old variables below from the data set; drop size_g sugar_g fat_g sodium_mg; run; title2 "Cereal data adjusted for serving size"; proc print data=set1(obs = 11); run; ******************************************************************; * Macros to produce dot plots; *Test case to make sure code works outside of a macro; proc sgplot data=set1; scatter x=shelf y=sugar / jitter jitterwidth=0.2; yaxis label="Sugar"; xaxis values=(1 to 4 by 1); run; %macro dotplot(var1); title2 "Dot plot for &var1"; proc sgplot data=set1; scatter x=shelf y=&var1 / jitter jitterwidth=0.2; yaxis label="&var1"; xaxis values=(1 to 4 by 1); run; %mend dotplot; %dotplot(Sugar); %dotplot(Fat); %dotplot(Sodium);