The script creates a demo dataset `sample_adsl` containing information on subjects and their treatment groups (`trta`, `trtan`). A macro `%count` is then defined, which takes as parameters the input dataset, variables to consider for sorting and counting, and the numerical range of treatment groups. The macro uses `PROC SQL` to count distinct subjects (`usubjid`) for each treatment group within the specified range and stores these counts in global macro variables (e.g., `bign0`, `bign1`, etc.). Finally, the macro is called with the appropriate parameters for the `sample_adsl` dataset and treatment groups 0 to 3.
Data Analysis
Type : CREATION_INTERNE
The `sample_adsl` dataset is created directly within the script using a DATA step. It does not depend on unmanaged external data sources or SASHELP libraries.
1 Code Block
DATA STEP Data
Explanation : This DATA step creates the `sample_adsl` dataset. It is populated with five observations, each representing a subject (`usubjid`) assigned to a treatment group (`trta` with its numerical version `trtan`). This dataset serves as a test basis for subject counting.
Explanation : This macro named `%count` is designed to count distinct subjects. It supports an input dataset (`data`), counting and sorting variables (`var`), and a range of treatment groups (`trts` to `trte`). Inside the macro, `PROC SQL` is used to create a temporary table `count` and then, through a `%do` loop, iterate over each treatment group. For each group, it counts unique subjects (`usubjid`) and stores the result in a dynamic global macro variable (e.g., `bign0`, `bign1`). The results are displayed in the SAS log via `%put`.
Copied!
%macro count(data=,var=,trts=,trte=);
proc sql noprint;
create table count as select &var. from &data. order by &var.;
%do i=&trts. %to &trte.;
%global bign&i.;
select count(distinct usubjid) into: bign&i. from count where trtan=&i;
%put bign&i. &&bign&i.;
%end;
quit;
%mend count;
1
%macro count(DATA=,var=,trts=,trte=);
2
PROC SQL noprint;
3
create TABLE count as select &var. from &DATA. order BY &var.;
4
%DO i=&trts. %to &trte.;
5
%global bign&i.;
6
select count(distinct usubjid) into: bign&i. from count where trtan=&i;
7
%put bign&i. &&bign&i.;
8
%END;
9
QUIT;
10
%mend count;
3 Code Block
MACRO %COUNT CALL
Explanation : This call executes the `%count` macro. It provides the previously created `sample_adsl` dataset, specifies the variables `trtan`, `trta`, and `usubjid` for the operation, and requests counting for treatment groups ranging from 0 to 3. This will generate global macro variables such as `bign0`, `bign1`, `bign2`, `bign3` containing the subject counts for each respective group.
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.
Copyright Info : Program Name : Bign_counter.sas
* Author : Balaji.M
* SAS Version : SAS 9.4 or higher
* Description : This SAS program is use to generate subject counts from adsl dataset with dummy treatment groups
in below example Drug C is counted with dummy values for testing purpose.
*Macro variable : data:- Input Dataset
var:- Variables used for counting and sorting purpose should be included
trts:- treatment group start numeric value
trte:- treatment group end numeric value
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.