Discover More Tips and Techniques on This Blog

Short Code Samples

1) IF-THEN-ELSE vs SELECT:

The SELECT Loop Multiple IF statements in a DATA Step can be replaced with the more efficient SELECT Loop. If you would normally write:

if region='South' then quarter=4;
else if region='North' then quarter=3;
else if region='East' then quarter=2;
else quarter=1;


You can accomplish the same thing with the SELECT Loop in a DATA Step:

select(region);
when('South') quarter=4;
when('North') quarter=3;
when('East') quarter=2;
otherwise quarter=1;
end;

source:www.usc.edu

2) IFC and IFN functions:new IF functions:

IFN(condition, true-numeric-value, false-numeric-value, missing-numeric-value):IFN returns a numeric value. It returns the true, false or missing value depending on whether the condition is true, false or missing.

IFC(condition, true-character-value, false-character-value, missing-character-value):IFC returns a character value. It returns the true, false or missing value depending on whether the condition is true, false or missing.

The IFN function is similar to the IFC function, except that IFN returns a numeric value whereas IFC returns a character value.

IFN evaluates the first argument, then logical-expression. If logical-expression is true (that is, not zero and not missing), then IFN returns the value in the second argument. If logical-expression is a missing value, and you have a fourth argument, then IFN returns the value in the fourth argument.

If logical-expression is false, IFN returns the value in the third argument. The IFN function, an IF/THEN/ELSE construct, or a WHERE statement can produce the same results However, the IFN function is useful in DATA step expressions when it is not convenient or possible to use an IF/THEN/ELSE construct or a WHERE statement.

source: whatsnew_10110.pdf from www.sas.com

Without IFC:

data new;
set old;
if safarmcd='A' then ord=1;
else if safarmcd='B' then ord=2;
run;

with IFC:

data new;
set old;
ord=ifc(safarmcd='A',1,2);
run;


without IFC:

data percent;
length para $20;
if arm='placebo' then percent=100*count/&a;
if arm='drug' then percent=100*count/&b;
if arm='total' then percent=100*count/&c;

if percent>=99.5 then para=put(count,4.)'('put(percent,5.1)'%)';
else if percent>=9.95 then para=put(count,4.)' ('put(percent,4.1)'%)';
else if percent>. then para=put(count,4.)' ('put(percent,3.1)'%)';
run;

With IFC:

data percent;
length para $20;
if arm='placebo' then percent=100*count/&a;
if arm='drug' then percent=100*count/&b;
if arm='total' then percent=100*count/&c;

if percent>=99.5 then para=put(count,4.)'('put(percent,5.1)'%)';
para=IFC(percent>=9.95,put(count,4.)' ('put(percent,4.1)'%)',put(count,4.)' ('put(percent,3.1)'%)');
run;


SAS Tips and Tricks

SAS TIPS AND TRICKS part1:

SAS TIPS AND TRICKS part2:



Tips and Tricks of SAS With Sample Code


SAS Tips
MirjanaSESUGpresentation

SAS Programming Tips[1]

Advanced SAS Programming Techniques (www.studysas.blogspot.com)


Base-SAS Tips, Tricks and Techniques -


VA Information Resource Center (VIReC) SAS Programming Efficiency ... -


The University of Texas at Austin SAS Tips Archive:


SAS Resource Tips:

CDISC and its IMPLEMENTATION

An Introduction to CDISC:

CDISC: Why SAS® Programmers Need to Know

CDISC Implementation Step by Step: A Real World Example

A Toolkit for CDISC Implementation

CDISC standards

How to test CDISC Operation data Model (ODM) in SAS

Creating Case Report Tabulations (CRTs) for an NDA Electronic Submission to the FDA


Implementation Guide

Study Data Tabulation Model


Update on CDISC Study Data Tabulation Model


Practical Methods for Creating CDISC SDTM Domain Data Sets from Existing Data


SAS® Dataset Content Conversion to CDISC Data Standards

IMPLEMENTATION OF CDISC STANDARDS

Sample CRF's and Protocol
CRFs (PDF - 773.4 KB)
Protocol (PDF - 2.0 MB)

direct link: https://biolincc.nhlbi.nih.gov/studies/

Ten Great Reasons to Learn SQL Procedure/ HOW TO WORK WITH SUBQUERY IN THE SQL PROCEDURE

Ten Great Reasons to Learn SQL Procedure

Top 10 List
# 1. Using the Pass-Through Facility
# 2. Joining Tables of Data
# 3. Creating and Using Views
# 4. Producing Reports
# 5. Using Summary Functions
# 6. Creating and Modifying Tables
# 7. Grouping Data
# 8. Ordering Data
# 9. Subsetting Data
# 10. Retrieving (Querying) Data

source: ssc.utexas.edu



WORKING WITH SUBQUERY IN THE SQL PROCEDURE

Example 1: Find patients who have records in table DEMO but not in table VITAL.

Proc SQL;
Select patid from demog
Where patid not in (select patid from vital);QUIT;
Result:
PATID
-----
150

Example 2: Find patients who didn’t have their blood pressures measured twice at a visit.
Proc SQL;
select patid from vital T1
where 2>(select count(*)
from vital T2
where T1.patid=T2.patid
and
T1.visid=T2.visid);QUIT;
Result:
PATID
-----
110
140

Example 3: Find patients who have the maximum number of visits.
Proc SQL;
Select distinct patid
from vitmean as a
Where not exists
(select visid from vitmean
Except
Select visid from vitmean as b
Where a.patid=b.patid);QUIT;
Result:
PATID
-----
120

Example 4: Find patients whose age is in the average age +/- 5 years.
Proc SQL;
Select patid
from demog
where age between
(select Avg(age)
from demog)-5
and
(select avg(age)
from demog)+5; QUIT;
Result:
PATID
------
110

Example 4: Find patients who didn’t have maximum number of visits.
Proc SQL;
Select patid
From vitmean as a
Group by patid
Having count(visid)
<(select max(cnt) from (select count(visid) as cnt from vitmean group by patid) ); QUIT; Result:
PATID
------
100
110
130
140

Example 5: Calculate the interval between this visit and previous visit for each patient visit.

proc sql;
select a.patid, a.visid,
intck('day', b.visdate, a.visdate)
as interval
from
(select distinct patid,
visid, visdate
from vital
where visid>'1') as a,
(select distinct patid,
visid, visdate
from vital
where visid<'4') as b where(input(a.visid,2.)-1 =input(b.visid,2.)) and a.patid=b.patid order by a.patid, a.visid; QUIT; Result:
PATID VISID INTERVAL
----------------------------
100 2 7
100 3 7
120 2 8
120 3 6
120 4 34
130 2 35
130 3 38
140 2 9

Example 6: Find patients who have exact same visits.
proc sql;
create table vital as
select distinct patid, visid
from vital;
select T1.PATID as PATID,
T2.PATID as PATID1
FROM
(select patid, visid from VITAL)
AS T1
inner join
(select patid, visid from VITAL)
AS T2
on T1.visid=T2.visid
and T1.patid < patid="T1.PATID)" patid="T2.PATID);" color="#cc33cc">RESULT:
PATID PATID1
-----------------
100 130


APPENDIX: EXAMPLE SAS DATA SETS For The ABOVE PROGRAMS:

Data demog;
input patid $1-3 age 5-6 sex $ 8;
datalines;
100 34 M
110 45 F
120 67 M
130 55 M
140 40 F
150 38 M
;
run;

data vital;
input patid $
visid $
visdate mmddyy10.
diabp
sysbp;
format visdate mmddyy10.;
datalines;
100 1 01/12/97 66 110
100 1 01/12/97 68 110
100 2 01/19/97 66 .
100 2 01/19/97 66 110
100 3 01/26/97 68 120
100 3 01/26/97 68 120
110 1 02/03/97 68 110
110 3 02/12/97 64 115
110 3 02/12/97 68 115
120 1 04/05/97 66 105
120 1 04/05/97 64 105
120 2 04/13/97 110 64
120 2 04/13/97 105 82
120 3 04/19/97 63 105
120 3 04/19/97 105 90
120 4 05/23/97 90 106
120 4 05/23/97 92 108
130 1 02/12/97 66 111
130 1 02/12/97 67 110
130 2 03/19/97 66 109
130 2 03/19/97 66 110
130 3 04/26/97 68 121
130 3 04/26/97 68 118
140 1 02/03/97 68 110
140 2 02/12/97 64 115
140 2 02/12/97 68 115
;
run;

source: www.nesug.org/proceedings/nesug98/dbas/p005.pdf

WHY SAS

Why SAS?

SAS is software where in they can use it in their domain and it is comparitively easy to learn as SAS® is neither a menu-driven nor a command driven application. Rather it relies on user-written scripts or “programs” that are processed when requested to know what to do. Because it is a script-based application, the key to being successful using SAS is learning the rule and tricks of writing scripts.

• Can process large data set(s)

• Easy to cope with multiple variables

• Can track all the operations on the data set(s)

• Can generate systematic output

• Summary statistics

• Graphs

• Regression results


WHY SAS IS THE ANSWER:

Clinical data is sensitive information that should be treated as a valuable asset as well as a regulated commodity. Not only can improper management of clinical data cause the invalidation of an entire clinical trial, but it may also result in strict remedies, including serious financial penalties, from the FDA.

At the time of this writing, the FDA has not issued revised CFR 21 Part 11 guidance. This indicates that the FDA is still struggling with the difficult issue of Part 11 requirements compliance for a clinical database. However, it is known that the FDA does request that all clinical DBMS prevent unauthorized access to data. This requires that data be password protected and allow updates only by authorized users of the clinical DBMS.

The FDA also requires maintenance of complete audit trails for clinical data. Both the entry and revision of clinical data is to be logged to indicate the user performing the action, the date and time of the action, as well as the reason for change of data.

These requirements and many others are all easy goals when working with the SAS System. In addition to being easy to use, SAS is also the choice of the FDA for receiving and reviewing clinical data. The FDA is still requesting SAS transport data sets as the standard for receiving electronically submitted data. At a minimum, each FDA reviewer is equipped with the SAS System Viewer.

Since the use of SAS is essential to clinical information management, keeping clinical data in SAS makes sense. SAS is the government and the industry standard for performing clinical analysis. Reporting is also effectively accomplished using SAS.


 Who can pursue SAS

Graduates & PGs from any discipline (MBAs, Commerce, Engineering Life sciences, Arts, Medicine, MCAs Statistics etc) can learn SAS.

 Applications

SAS applications are used in
• Financial Services
• Banking
• Insurance
• Retail
• Manufacturing
• Media
• Education
• Communications
• Government
• Hospitality & Entertainment
• SAS Solutions for Small to Medium Businesses
• Aerospace
• Health Insurance
• Automotive
• Energy & Utilities
• Life Sciences
• Government
• Federal Government
• State Government

In the given industries SAS can be used in the following areas

• Customer Relationship Mgmt
• Financial Intelligence
• Human Capital Mgmt
• Profitability Management
• Performance Management
• Risk Management
• Business Intelligence
• Reporting
• Query & Analysis
• Microsoft Office Integration
• Forecasting & Econometrics
• IT Management
• Activity-Based Management
• Compliance (Basel II, Sarbanese Oxly Act etc.)
• Service Intelligence • Supplier Intelligence
• Supply Chain Intelligence
• Web Analytics
•On Demand Solutions
• Data Integration & ETL
• Connectivity & Metadata
• Data Cleansing & Enrichment
• ETL
• Migration & Synchronization
• Data Federation• OLAP
• Integrated Analytics
• Visualization
• Analytics
• Statistics
• Data & Text Mining
• Optimization
• Model Mgmt. and Deployment
• Quality Improvement
• Enterprise Intelligence Platform
• Data Integration & ETL
• Business Intelligence
• Analytics
• Intelligence Storage

source: oceantech and SUGI 29 proceeding


Disclosure:

In the spirit of transparency and innovation, I want to share that some of the content on this blog is generated with the assistance of ChatGPT, an AI language model developed by OpenAI. While I use this tool to help brainstorm ideas and draft content, every post is carefully reviewed, edited, and personalized by me to ensure it aligns with my voice, values, and the needs of my readers. My goal is to provide you with accurate, valuable, and engaging content, and I believe that using AI as a creative aid helps achieve that. If you have any questions or feedback about this approach, feel free to reach out. Your trust and satisfaction are my top priorities.