Hi everyone, i have a data set similar to below with 60 columns(both numeric and character). I'm planning to take then in to loop one by one and perform descriptive analysis. before they enter into the loop they must undergo a checking for their datatype. This is an interesting task which i'm planning to perform by the help of using arrays(as I've heard of the power of using arrays and used before).
After going through several white papers i have came up with a sample untested code and it would be great to have your help to take my array learning to a next level.
Kindly do comment.
data temp;
input subjid AGE SEX BMI SODIUM INFECTION;
cards;
01001 56 F 22.3 34.5 Y
01001 60 M 29.3 41.5 N
01001 35 F 26.3 22.5 Y;
01001 23 M 19.3 34.5 Y;
01001 34 F 18.3 41.5 Y;
;
run;
%macro descriptive(first=, last= );
data _null_;
set temp;
array variables AGE--INFECTION;
%do over variables;
%if datatyp(variables[i] eq CHARACTER) %then %do;
proc freq data=temp;
var variables[i];
run;
%end;
%else %if datatyp(variables[i] eq NUMERIC) %then %do;
proc means data =temp;
var variables[i];
run;
%end;
%mend descriptive;
Some references for you:
Here's a tutorial on using Arrays in SAS
https://stats.idre.ucla.edu/sas/seminars/sas-arrays/
UCLA introductory tutorial on macro variables and macros
https://stats.idre.ucla.edu/sas/seminars/sas-macros-introduction/
Tutorial on converting a working program to a macro
This method is pretty robust and helps prevent errors and makes it much easier to debug your code. Obviously biased, because I wrote it 🙂 https://github.com/statgeek/SAS-Tutorials/blob/master/Turning%20a%20program%20into%20a%20macro.md
Examples of common macro usage
https://communities.sas.com/t5/SAS-Communities-Library/SAS-9-4-Macro-Language-Reference-Has-a-New-Ap...
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.