Creating Test Datasets


(Author: Roland Rashleigh-Berry                                                                    Date: 08 Aug 2011)









To see a demonstration of the main reporting macros %unistats and %npcttab you will need some datasets as input. This section gives you the code to create two datasets in your sasuser area for use in these demonstrations.

If you are using a laptop for these demonstrations or your PC at home then the following code and all the demonstration code will function using SAS® Learning Edition . You will learn more if you actually submit the code and see the results and SAS Learning Edition is an inexpensive and worthwhile alternative to owning a full copy of SAS® software.

Note that at the start of the code, the library containing the macros is added to the sasautos search path. I did this because it calls the macro %age to calculate age as there is no SAS software function to do this (at least not that I know of). What you have to do is to copy and paste the code in an interactive SAS software session or run it from batch so that it creates two datasets, sasuser.demog and sasuser.adv. These will then be the datasets used to demonstrate the functions of the %unistats and %npcttab macro in later sections. You will have to amend the code so that the macros are in the correct location.

Check your SASUSER library before running this code. If you have datasets named DEMOG or ADV in your sasuser library that were not created for Spectre testing then BACK THEM UP before running this code as this code will overwrite them.
 
/* Makes sasuser.demog and sasuser.adv datasets for testing */

options fmtsearch=(sasuser);

proc format lib=sasuser;
  value racecd
  1="CAUCASIAN"
  2="BLACK"
  3="ASIAN"
  4="HISPANIC"
  5="OTHER"
  ;
  value sexcd
  1="MALE"
  2="FEMALE"
  ;
  *- 1 and 2 for male, 3 and 4 for female -;
  value trtgencd
  1="Ambident@(1g/day)"
  2="Betamax@(500mg/day)"
  3="Ambident@(1g/day)"
  4="Betamax@(500mg/day)"
  ;
  value trtcd
  1="Ambident (1g/day)"
  2="Betamax (500mg/day)"
  3="No treatment"
  ;
  value trtnarr
  1="Ambident@(1g/day)"
  2="Betamax@(500mg/day)"
  3="No@treatment"
  ;
  *- 1-9 = Female, 11-19 = Male -;
  value trtsex
  1="Ambident@(1g/day)"
  2="Betamax@(500mg/day)"
  9="Total"
  11="Ambident@(1g/day)"
  12="Betamax@(500mg/day)"
  19="Total"
  ;
  *- 1-9 = study 101+102, 11-19 = study 301+302 -;
  value trtcdx 
  1="Placebo" 
  2="Drug A" 
  3="Drug B" 
  9="Total"
  11="Placebo" 
  12="Drug A" 
  13="Drug B" 
  19="Total"
  ;
  value NY
  0="NO"
  1="YES"
  ;
  value intensity
  1="Mild"
  2="Moderate"
  3="Severe"
  ;
run;

data sasuser.demog;
  informat dob date7. 
           trtcd sexcd racecd weight height 
           patno invid sitecd fascd comma13.;
  input patno invid sitecd fascd dob 
        trtcd sexcd racecd weight height;
  age=%age(dob,"01jan2006"d);

  *- assign a random study treatment arm -;
  trtcdx=ceil(ranuni(88)*6);
  if trtcdx>3 then trtcdx=trtcdx+7;

  *- set up the gender-derived treatment arm -;
  *- with males shown after females -;
  trtsex=trtcd;
  if sexcd=1 then trtsex=trtcd+10;

  format dob date9. sexcd sexcd. racecd racecd. 
         trtcd trtcd. weight height 5.1 age 3.
         trtsex trtsex. trtcdx trtcdx. fascd ny.;
  label patno="PATIENT NUMBER"
        invid="INVESTIGATOR ID"
        sitecd="SITE CODE"
        fascd="FULL ANALYSIS SET (N/Y)"
        dob="DATE OF BIRTH"
        trtcd="TREATMENT REGIMEN"
        trtsex="GENDER/TREATMENT REGIMEN (1+2 female, 11+12 male)"
        sexcd="GENDER CODE"
        racecd="RACE CODE"
        weight="WEIGHT (KG)"
        height="HEIGHT (CM)"
        age="AGE (YEARS)"
        ;
  cards;
  100 1000 10 1 10oct85 1 1 1 78.1 200
  101 1000 10 1 20nov89 2 1 2 65.5 175
  102 1000 10 1 10oct75 1 2 1 79.6 212
  103 1000 10 0 20nov79 2 2 3 75.3 186
  200 2000 20 1 10oct65 1 1 1 78.1 200
  201 2000 20 1 20nov69 2 1 3 65.5 175
  202 2000 20 1 10oct85 1 2 1 79.6 212
  203 2000 20 1 20nov89 2 2 5 75.3 186
  300 3000 30 1 10oct75 1 1 2 78.1 200
  301 3000 30 1 20nov79 2 2 2 65.5 175
  302 3000 30 0 10oct65 1 2 1 79.6 212
  303 3000 30 1 20nov69 2 2 3 75.3 186
  400 4000 40 1 10oct85 1 2 1 78.1 200
  401 4000 40 1 20nov89 2 2 2 65.5 175
  402 4000 40 0 10oct75 1 1 1 79.6 212
  403 4000 40 1 20may79 2 2 3 75.3 186
  404 4000 40 1 18jun70 1 1 3 76.6 190
  500 5000 50 1 10oct85 2 1 1 78.1 200
  501 5000 50 1 20nov89 1 2 2 65.5 175
  502 5000 50 0 10oct75 2 1 1 79.6 212
  503 5000 50 1 20may79 1 2 3 75.3 186
  901 9000 90 0 13may78 3 2 2 74.5 183
  ;
run;

proc print data=sasuser.demog;
  id patno invid;
run;

data adv;
  length amsoc ampt $ 60;

  amsoc="Gastrointestinal disorders";
  ampt="Abdominal pain NOS";output;
  ampt="Constipation";output;
  ampt="Diarrhoea NOS";output;
  ampt="Nausea";output;
  ampt="Vomiting NOS";output;

  amsoc="General disorders and administration site conditions";
  ampt="Chest pain";output;
  ampt="Pain NOS";output;

  amsoc="Musculoskeletal and connective tissue disorders";
  ampt="Back pain";output;
  ampt="Pain in extremity";output;

  amsoc="Nervous system disorders";
  ampt="Headache";output;
  ampt="Tremor";output;

  amsoc="Psychiatric disorders";
  ampt="Anxiety";output;
  ampt="Insomnia";output;

  amsoc="Respiratory, thoracic and mediastinal disorders";
  ampt="Cough";output;
  ampt="Dyspnoea";output;

  amsoc="Vascular disorders";
  ampt="Hypertension NOS";output;
  ampt="Hypotension NOS";output;
run;
 

data sasuser.adv;
  do i=1 to nobsdem;
    set sasuser.demog(keep=patno invid fascd) point=i nobs=nobsdem;
    do j=5 to ceil(ranuni(111)*30);
      intensity=ceil(ranuni(333)*3);
      ptr=ceil(ranuni(222)*nobsadv);
      set adv point=ptr nobs=nobsadv;
      output;
    end;
  end;
  stop;
  drop j;
  format intensity intensity.;
run;

proc print data=sasuser.adv;
  id patno invid;
run;


 

Use the "Back" button of your browser to return to the previous page.

contact the author














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.