Skip to content

Instantly share code, notes, and snippets.

@Ray4hz
Ray4hz / set
Last active December 10, 2015 01:24
set
/*--------------------------------------------------------------*/
/* Index and Double-set */
/*--------------------------------------------------------------*/
/* This example is to demonstrate the use of proc datasets */
/* (index) and double-set. */
/* */
/*--------------------------------------------------------------*/
/* The first data set TRANSACTION is a lookup table. */
/* The second data set MASTER is to get multiple */
/* observations per lookup observation. */
@Ray4hz
Ray4hz / setcat
Created November 16, 2012 02:29
Create a categorical variable with different groups in the datasets
* generate random categorical variables;
%macro setcat(indsn=, outdsn=, rn=, varname=, len=40, cat=, ncat=);
data copy;
set &indsn;
seq = _n_;
run;
* put the number of each category in ncat1, ncat2,...ncati, count the total number of categories;
%let i = 1;
%do %while (%cmpres(%scan(&ncat., &i., "|")) ne );
%let ncat&i. = %cmpres(%scan(&ncat., &i., "|"));
@Ray4hz
Ray4hz / setr
Created November 16, 2012 02:18
Create random number along with the observation in the dataset
* create random number in a dataset according to its obs;
%macro setr(indsn=, outdsn=, rn=);
%let dsid = %sysfunc(open(&indsn));
%global nobs;
%let nobs = %sysfunc(attrn(&dsid, nlobs));
%let rc = %sysfunc(close(&dsid));
data tem;
set &indsn;
rnum&rn = _n_;
run;
@Ray4hz
Ray4hz / s_dm
Created November 15, 2012 21:23
To generate SDTM DM
/*******************************************************************************************************************
Project: BAN-AA-01
Program: s_dm
Des: To generate SDTM DM;
Input:
Output:
Programmer: Ray (Hang Zhong)
Created:
QCer:
QC date: 11/15/2012