This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
*path to the zip file; | |
filename src zip "/home/fkhurshed/Demo2/P_DR2IFF.zip"; | |
*path to where to save the xpt file; | |
filename xl "/home/fkhurshed/Demo2/P_DR2IFF.xpt" ; | |
*extract file from zip - P_DR2IFF.XPT in the code below is the name of the file in the zipped file that is to be extracted; | |
data _null_; | |
/* using member syntax here */ | |
infile src(P_DR2IFF.XPT) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*Author: F.Khurshed | |
Date: 2022-10-07*/ | |
*create library to store format catalog; | |
libname demo '/home/fkhurshed/Demo1'; | |
proc format; | |
value age_fmt | |
low - 12 = 'Child' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*This program illustrates how to loop through by calendar months and calculate a moving statistic*/ | |
data have; | |
set sashelp.stocks; | |
run; | |
*sort for faster processing and add index; | |
proc sort data=have out=have (index=(date)); | |
by date; | |
run; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
*This macro will export a file to a data set and split it based on the number of records per sheet; | |
%macro export_split (dsn=, size=); | |
%*Get number of records and calculate the number of files needed; | |
data _null_; | |
set &dsn. nobs=_nobs; | |
call symputx('nrecs', _nobs); | |
n_files=ceil(_nobs/ &size.); | |
call symputx('nfiles', n_files); | |
stop; | |
run; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*This is an example of how to create an Other category for everything except the top 3*/ | |
*not ideal, other becomes first format - will look into how to make it last value; | |
*get counts; | |
proc freq data=sashelp.class order = freq; | |
table age / out=counts; | |
run; | |
*create format; | |
data counts_fmt; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
*This example demonstrates how you can merge data with a formatted variable and not have to create a new variable; | |
data stocks_A; | |
set sashelp.stocks; | |
where stock='IBM'; | |
format date yymmn6.; | |
*keep only relevant variables for testing; | |
keep date open; | |
*rename to identify source; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
*How to selectively filter your list of variables in a SAS data set with a pattern but not one that uses SAS variable shortcuts; | |
options mprint symbolgen; | |
%macro select(lib =, ds_in=, pattern=, ds_out=); | |
proc sql noprint; | |
select nliteral(name) into :var_list separated by ' ' | |
from dictionary.columns | |
where libname = upcase("&lib") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*This is an example of how to search through a list of terms and see if a field contains any of the values*/ | |
*Make fake data to show example; | |
*terms to search for; | |
data terms; | |
set sashelp.baseball (obs=5); | |
search_term = substr(team,1,3); | |
keep search_term;; | |
run; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#This program centers all variables | |
#This is also called standardization - each variable minus the mean. | |
library(tidyverse) | |
#generate fake data | |
df <- structure(list(day = c(2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
One common issue with using SQL pass through is that you sometimes want to use data that is on your SAS server. Rather than pass this information to the server, to be used in a subquery or join, you can pass the values directly by dynamically generating the code and lookup lists | |
*/ | |
%let age = 14; | |
data test; | |
set sashelp.class end = eof;; | |
where age = &age.; |
NewerOlder