This file contains hidden or 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
%macro drop_missing_pct(input_dsn = , output_dsn=, pct = , id_vars=); | |
*input_dsn = input data set name; | |
*output_dsn = output data set name; | |
*pct = missing percent, variables with a percentage of missing above this value are dropped; | |
*id_vars = space delimited list of variables that you do not want to include in the analysis such as ID variables; |
This file contains hidden or 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
*https://communities.sas.com/t5/SAS-Programming/combining-multiple-columns/m-p/705769 | |
/*This example illustrates how to combine variables from labels or variable names | |
from a list of indicator variables | |
Author: F. Khurshed | |
Date: 2020-12-14 | |
*/ | |
data have; |
This file contains hidden or 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
/*Modified from this question on SO: https://stackoverflow.com/questions/65219061/sas-loop-create-columns-from-the-records-which-are-having-a-value | |
Initial answer from Richard D. | |
*/ | |
*sample data; | |
data have; | |
input id found code $; | |
datalines; | |
1 1 001 | |
2 0 v58 |
This file contains hidden or 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 exports all files from a library into CSV files. | |
Author: F. Khurshed | |
Date: 2020-09-25 | |
*/ | |
options dlcreatedir; | |
proc options option=dlcreatedir; | |
run; |
This file contains hidden or 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 goes over how to create a data set with all values. In this case item_id should have values 1 through 4 for every record | |
Missing values are included for the missing resp | |
Question originally from here: https://communities.sas.com/t5/SAS-Programming/How-to-format-this-data/m-p/665054 | |
*/ | |
*fake data; | |
data have; | |
input item_id $ resp; | |
datalines; |
This file contains hidden or 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
month <- c(12,3,6,2,3,7) | |
month.abb[month] | |
#[1] "Dec" "Mar" "Jun" "Feb" "Mar" "Jul" | |
#To apply as label in graphs: | |
factor(month.abb[serviceMonth], levels=month.abb) |
This file contains hidden or 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 save an RDS file with the date in the name | |
#file name | |
myfileName <- "exampleData" | |
#create full file name including date and extension | |
myfilePath <- paste0(getwd(), "/", myfileName, "_" ,Sys.Date(), ".RDS") | |
#pass variable to save function | |
saveRDS(mpg, myfilePath) |
This file contains hidden or 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 shows how to : | |
#1. customize the order of bars in a bar plot | |
#2. format legend | |
#3. Add labels to axis, graph title, legend | |
#4. Create clustered bar chart | |
#F.Khurshed | |
#2020-05-11 | |
#create fake data to play with | |
demo <- dput(structure(list(days_stay = c("<=30", "<=30", "120+", "31 to 60", |
This file contains hidden or 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 demonstrates how to ensure all levels are in your report | |
using the preloadfmt option*/ | |
data raw; | |
input person firsttest $ secondtest $; | |
datalines; | |
1 Good Good | |
2 Poor Good | |
3 Good Bad |
This file contains hidden or 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
*Create ranks for variables value; | |
proc rank data=sashelp.class out=class_ranked | |
/* (where= (rank_weight < 4)) */ | |
; | |
var weight; | |
ranks rank_weight; | |
run; | |
*display output; | |
title 'Unsorted but ranked'; |