Showing posts with label sas. Show all posts
Showing posts with label sas. Show all posts

Saturday, April 11, 2020

SAS Practice Examples


Create a Student table with studentnum, quarter, math, science, english marks?

data Student;
 input studentnum $ quarter math science english;
 datalines;
 1001 1 70 80 76
 1001 2 80 80 78
 1001 3 90 85 80
 ;
run;

Add 4th quarter marks as a new record and create a new Student_1 table?

data Student_1;
 set Student end=eof;
 output;
 if eof then do;
   studentnum = '1001';
   quarter = 4;
   math = 88;
   science = 90;
   english = 88;
   output;
 end;
run;

Add the total for each quarter?

data Student_marks_total;
 set Student_1;
 total = math + science + english;
run;

Add the average for each column including the total as a new row in the bottom?

data Student_marks_avg;
 
 set Student_marks_total end=eof;
 drop sum_math sum_science sum_english sum_total;
 retain sum_math sum_science sum_english sum_total 0;
 
 sum_math = sum_math + math;
 sum_science = sum_science + science;
 sum_english = sum_english + english;
 sum_total = sum_total + total;
 
 output;
 
 if eof then do;
  studentnum = 'avg';
  quarter = .;
  math = sum_math / 4;
  science = sum_science / 4;
  english = sum_english / 4;
  total = sum_total / 4;
  output;
 end;
run; 

Sort the Student_1 table by reversing the quarter?

proc sort data=student_1 out=student_1_sort_by_quarter;
 by descending quarter;
run;

Combine Sales, Delivery employee datasets as Marketing dataset?

data Sales;
 input empno empname $;
 datalines;
 1001 Daniel
 1002 Peter
 ;
run;

data Delivery;
 input empno empname $;
 datalines;
 1003 Simon
 1004 Chris
 ;
run;

data Marketing;
 set Sales Delivery;
run;

Merge a Student's arts and groups marks into a single dataset?

data student_arts;
 input studentnum english spanish latin;
 datalines;
 1001 80 70 78
 ;
run;

data student_groups;
 input studentnum math science history;
 datalines;
 1001 88 78 89
 ;
run;

data student_arts_and_groups;
 merge student_arts student_groups;
 by studentnum;
run;

Is it possible to create a table in a simple way with couple of records and couple of columns?

data blah;
 firstname = 'Sean'; 
 lastname = 'Connery';
run;

Or with two records

data blah;
 firstname = 'Sean'; 
 lastname = 'Connery';
 output;
 firstname = 'Matt';
 lastname = 'Damon';
 output;
run;

Calculate average and grade the student based on this grading guidelines?
failed: below 35
ordinary: > 35 and <= 50
second: > 50 and <= 60
first: > 60 and <= 70
distinction: > 70

data Student;
 input studentnum $ math science english;
 datalines;
 1001 40 50 46
 1002 60 60 68
 1003 90 85 80
 1004 10 20 23
 ;
run;

data Student_grading;
 set Student;
 
 average = (math + science + english) / 3;
 average = Round(average, 0.01);
 
 length grading $ 12;
 
 if average > 35 and average <= 50 then grading = 'ordinary';
 else if average > 50 and average <= 60 then grading = 'second';
 else if average > 60 and average <= 70 then grading = 'first';
 else if average > 70 then grading = 'distinction';
 else grading = 'failed';
 
run;

Based on Student marks, decide the grading and add some comments?
(NOTE: more than one action in if-then statement, so you have to use do)

data student;
 input studentnum marks;
 datalines;
 1001 49
 1002 89
 1003 34
 1004 89
 ;
run;

data student_report;
 set student;
 if marks > 50 then do;
  result = 'pass';
  comments = 'eligible to go to next level';
 end;
 else do;
  result = 'fail';
  comments = 'not eligible to next level';
 end;
run;

How to add a column with table name?

data report_card;
 set student_grading indsname=name;
 tablename=scan(name,2);
run;

Create a temp dataset out of Student dataset using SQL?

proc sql;
 create table student_temp as
 select * from student;
quit;

Add numbers 1 to 5 and give the sum?

data sum_1_to_5;
 sum = 0;
 do i = 1 to 5;
 sum = sum + i;
 end;
 drop i;
run;

Nik has 10 dollars. Vik has 16 dollars. Keep giving Nik a dollar per day till they both have equal money?
(Note: Use Do while loop)

data level_the_brothers;
 nik_money = 10;
 vik_money = 16;
 
 do while (nik_money < vik_money);
  nik_money = nik_money + 1;
 end;
 
 final_nik_money = nik_money;
 final_vik_money = vik_money;
 
 drop nik_money vik_money;
run;

Nik has 10 dollars. Vik has 16 dollars. Keep giving Nik a dollar per day till they both have equal money?
(Note: Use Do until loop)

data level_the_brothers;
 nik_money = 10;
 vik_money = 16;
 
 do until (nik_money = vik_money);
  nik_money = nik_money + 1;
 end;
 
 final_nik_money = nik_money;
 final_vik_money = vik_money;
 
 drop nik_money vik_money;
run;

Find the total, average marks of students if all 6 subjects marks are provided for each student?

data array_example;
 input studentnum s1 s2 s3 s4 s5 s6;
 array s(6) s1-s6; /* Hint - array element names match column names */
 marks_total = sum(of s(*));
 marks_avg = round(mean(of s(*)), 0.01);
 datalines;
 1001 78 56 45 34 75 65
 1002 56 67 78 89 45 34
 ; 
run;

Saturday, January 25, 2020

SDTM in a nutshell

Beautifully explained the practical methods for creating CDISC SDTM tables:

https://support.sas.com/resources/papers/proceedings/pdfs/sgf2008/207-2008.pdf

Golden words: Analyses are "one proc away" from ADaM data. 

Other important SAS related references:

SAS clinical questions and answers: https://tekslate.com/sas-clinical-interview-questions-and-answers

There is a listing of sample graphs and example code: https://support.sas.com/en/knowledge-base/graph-samples-gallery.html

Details of Oncology studies and a relation between SDTM, ADaM and Controlled Terminology: https://www.pharmasug.org/proceedings/2018/DS/PharmaSUG-2018-DS06.pdf

Powerpoint slides details on ADaM tables and RECIST 1.1: https://www.cytel.com/hubfs/0-library-0/pdfs/CDISCJourneyonSolidTumorusingRECIST1.1.pdf

Again, it is a listing of sample graphs: http://support.sas.com/sassamples/graphgallery/PROC_SGPLOT.html

https://www.cdisc.org/system/files/all/event/restricted/2018_US/6B-CDISC-ADaM_Overview_-_Minjoe.pdf

https://www.cdisc.org/system/files/all/event/restricted/2017_International/INTX17%20Session%203%20Track%20A_Soloff.pdf

https://www.lexjansen.com/pharmasug/2018/DS/PharmaSUG-2018-DS24.pdf

https://www.lexjansen.com/pharmasug/2010/HW/HW06.pdf

https://www.quantics.co.uk/blog/an-introduction-to-integrated-summary-of-safety-and-integrated-summary-of-effectiveness-iss-and-ise/

https://blogs.sas.com/content/iml/2011/09/19/count-the-number-of-missing-values-for-each-variable.html

https://blogs.sas.com/content/iml/2012/04/02/count-missing-values-in-observations.html

https://journals.lww.com/anesthesia-analgesia/Fulltext/2018/09000/Survival_Analysis_and_Interpretation_of.32.aspx

https://www.lexjansen.com/pharmasug-cn/2014/CD/PharmaSUG-China-2014-CD03.pdf

https://www.lexjansen.com/phuse/2018/ds/DS03_ppt.pdf

Graphs from Robert Allison: https://robslink.com/SAS/Home.htm

About ADaM flags: https://www.pharmasug.org/proceedings/2013/PO/PharmaSUG-2013-PO11.pdf

http://www.stattutorials.com/SAS/

Oncology Survival Plot: https://support.sas.com/rnd/datavisualization/papers/Annotate_Your_SGPLOT_Graphs.pdfhttps://support.sas.com/rnd/datavisualization/papers/Annotate_Your_SGPLOT_Graphs.pdf

Survival analysis (Time-to-event analysis) is the process of measuring the length of time to the event. The event could be progress-free survival or overall survival or objective response rate. It may not be possible to measure the length of time for some patients because the patient disappeared or a bus hit him, or the study called off, etc. The missing data related to that patient is called the censored data.

Proc lifetest is useful to get the survival plot in a clinical trial. Also it provides multiple survival plots between two treatments. In the TIME statement, the survival time variable, Days, is crossed with the censoring variable, Status, with the value 0 indicating censoring.


The ADSL data structure has one record for one subject and contains subject-level population flags indicating whether subjects are in efficacy, safety, pharmacokinetic, pharmacodynamic, food effect, or dose proportionality analyses. In the Basic Data Structure (BDS) data sets, common record-level analysis flags include: recheck flags, flags for exclusion, baseline flags, early termination identifiers, and treatment-emergent flags.



Friday, August 19, 2016

Statistical Analysis System (SAS)


  • What does SAS stands for?
    • Statistical Analysis System
  • Who was the founder of SAS?
    • Jim Goodnight
  • How long SAS been around?
    • Around 30 years
  • What do you do with SAS software?
    • Gather, massage and manage the data, analyze the data, generate reports based on data.
  • What is the SAS software comprised of?
    • SAS Server to collect and save data, SAS Applications such as Enterprise Guide, SAS add-on for Microsoft Office, SAS Web Report Guide.
  • What are the SAS data access products?
    • SAS/ACCESS products that run on SAS Server.
  • Where can you download SAS software at free of cost?
  • What is a task in Enterprise Guide?
    • Tasks are the built-in wizards of Enterprise Guide.
  • Name couple of Enterprise Guide tasks?
    • Query Builder, Graphs, Reports, etc.
  • Why do you use charts in SAS?
    • To summarize the data.
  • Explain the basic mathematical terms mean, median, mode, range and give an example?
    • Mean is the average of all given numbers
    • Median is the middle number in the given numbers when arranged from smallest to largest
    • Mode is the number that appears the most in the given numbers
    • Range is the difference between the largest and smallest numbers in the given numbers
    • Let's find mean, median, mode, range of the given numbers 10, 18, 11, 11, 15
    • Mean: (10+18+11+11+15) / 5 = 13
    • Median: put the numbers in order: 10,11,11,15,18...and pick the middle number, 11
    • Mode: most appeared number is 11
    • Range: 18 (largest number) - 10 (smallest number) = 8
  • List some of the top pharmaceutical companies in USA?
  • Name some of the top clinical research organizations (CRO)?
    • Qunitiles, Covance, Parexel, Icon, INC, PPD, inVentiv, PRA, CRLI, WuXi
  • Name some of the top health foundations?
    • Bill & Melinda Gates Foundation, Robert Wood Johnson Foundation, Kresge Foundation, Nemours, W.K.Kellogg Foundation, Kaiser Parmanente.
  • Where can I learn more about Clinical Studies?
  • What are the clinical trial phases?
  • What is an IND Application?
    • IND stands for Investigational New Drug.
    • The drug sponsors file IND application to get the exemption from FDA to ship the experimental drug across the state lines (the intention is to use the drug in animal studies and human clinical trials). 
    • IND Application should have information in 3 broad areas: Animal Pharmacology and toxicity studies, Manufacturing information, Clinical Protocols and investigator information.
    • There are 3 IND types: Investigator IND, Emergency use IND, Treatment IND
    • Once the IND is submitted, the sponsor must wait 30 calendar days before initiating any clinical trials.
    • Read more at fda.gov
  • What is NDA Application?
    • NDA stands for New Drug Application.
    • The drug sponsors file NDA application with FDA to get the approval to sell the drug.
    • The data collected from IND becomes part of NDA.
    • Read more at fda.gov
  • What is the format of a proc step? (See for more details: http://www2.sas.com/proceedings/sugi29/256-29.pdf)