The script begins by creating two distinct datasets, 'males' and 'females', using DATA steps with in-line data (datalines). It then executes the PROC FREQ procedure on each table to calculate the frequency of ages by sex. The main part of the code is the definition of a '%multfreq' macro. This macro is designed to automate the execution of PROC FREQ on a list of datasets and for a specified list of variables, thus offering great flexibility for repetitive analyses. Finally, the macro is called to process the two previously created tables.
Data Analysis
Type : CREATION_INTERNE
Data for the 'males' and 'females' tables are created directly within the script using 'datalines' statements within two separate DATA steps. No external data source is required.
1 Code Block
DATA STEP Data
Explanation : This block creates the 'males' table from internal data provided via 'datalines'. The data contains information about male individuals.
Copied!
data males;
infile datalines dlm='|' dsd missover;
input NAME : $8. SEX : $1. AGE : best32. HEIGHT : best32. WEIGHT : best32.;
label ;
format ;
datalines4;
Alfred|M|14|69|112.5
Henry|M|14|63.5|102.5
James|M|12|57.3|83
Jeffrey|M|13|62.5|84
John|M|12|59|99.5
Philip|M|16|72|150
Robert|M|12|64.8|128
Ronald|M|15|67|133
Thomas|M|11|57.5|85
William|M|15|66.5|112
;;;;
run;
1
DATA males;
2
INFILEDATALINES dlm='|' dsd missover;
3
INPUT NAME : $8. SEX : $1. AGE : best32. HEIGHT : best32. WEIGHT : best32.;
4
label ;
5
FORMAT ;
6
datalines4;
7
Alfred|M|14|69|112.5
8
Henry|M|14|63.5|102.5
9
James|M|12|57.3|83
10
Jeffrey|M|13|62.5|84
11
John|M|12|59|99.5
12
Philip|M|16|72|150
13
Robert|M|12|64.8|128
14
Ronald|M|15|67|133
15
Thomas|M|11|57.5|85
16
William|M|15|66.5|112
17
;;;;
18
RUN;
2 Code Block
DATA STEP Data
Explanation : This block creates the 'females' table from internal data provided via 'datalines'. The data contains information about female individuals.
Copied!
data females;
infile datalines dlm='|' dsd missover;
input NAME : $8. SEX : $1. AGE : best32. HEIGHT : best32. WEIGHT : best32.;
label ;
format ;
datalines4;
Alice|F|13|56.5|84
Barbara|F|13|65.3|98
Carol|F|14|62.8|102.5
Jane|F|12|59.8|84.5
Janet|F|15|62.5|112.5
Joyce|F|11|51.3|50.5
Judy|F|14|64.3|90
Louise|F|12|56.3|77
Mary|F|15|66.5|112
;;;;
run;
1
DATA females;
2
INFILEDATALINES dlm='|' dsd missover;
3
INPUT NAME : $8. SEX : $1. AGE : best32. HEIGHT : best32. WEIGHT : best32.;
4
label ;
5
FORMAT ;
6
datalines4;
7
Alice|F|13|56.5|84
8
Barbara|F|13|65.3|98
9
Carol|F|14|62.8|102.5
10
Jane|F|12|59.8|84.5
11
Janet|F|15|62.5|112.5
12
Joyce|F|11|51.3|50.5
13
Judy|F|14|64.3|90
14
Louise|F|12|56.3|77
15
Mary|F|15|66.5|112
16
;;;;
17
RUN;
3 Code Block
PROC FREQ
Explanation : These two procedures perform a frequency analysis on the 'males' and 'females' tables, respectively. They calculate the cross-distribution of 'sex' and 'age' variables and store the results in tables 'u01' and 'u02'.
Explanation : Definition of the '%multfreq' macro. It takes as parameters a list of datasets ('dsnlist'), a list of frequency tables to generate ('tables'), and a 'where' condition. The macro loops through each dataset and executes PROC FREQ for each requested frequency table, creating an output dataset for each.
Explanation : Call to the '%multfreq' macro to perform frequency analysis on the 'males' and 'females' tables. The requested frequency table is the cross-distribution of 'sex' and 'age'.
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.
SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. WeAreCAS is an independent community site and is not affiliated with SAS Institute Inc.
This site uses technical and analytical cookies to improve your experience.
Read more.