Skip to content

Instantly share code, notes, and snippets.

@statgeek
statgeek / prompt_building_blocks.rmd
Created February 27, 2025 16:30
GenAI Prompt Building Blocks
The seven building blocks of a good prompt are:
Role 
Task 
Goal 
Audience 
Tone 
Format 
Sample 
"I want you to become my Prompt Creator. Your goal is to help me craft the best possible prompt for my needs. The prompt will be used by you, GPT. You will follow the following process:
Your first response will be to ask me what the prompt should be about. I will provide my answer, but we will need to improve it through continual iterations by going through the next steps.
Based on my input, you will generate three sections: a) Revised prompt: Provide your rewritten prompt. It should be clear, concise, and easily understood by you. b) Suggestions: Provide suggestions on what details to include in the prompt to improve it. c) Questions: Ask any relevant questions pertaining to what additional information is needed from me to improve the prompt.
We will continue this iterative process with me providing additional information to you and you updating the prompt in the Revised prompt section until it's complete."
@statgeek
statgeek / r_databricks_save_dataframe_catalog.r
Created July 16, 2024 15:37
R - Databricks - Write table to catalog
#This program downloads some data from Statistics Canada and saves it in a databricks catalog
#F. Khurshed
#2024-07-16
#installl and load relevant packages
install.packages("cansim")
install.packages("sparklyr")
library(cansim)
library(sparklyr)
@statgeek
statgeek / tablen.sas
Created May 10, 2024 15:11
TableN Macro - Author Jeff Meyers
/*------------------------------------------------------------------*
| MACRO NAME : tablen
| SHORT DESC : Creates a descriptives table of multiple variables
*------------------------------------------------------------------*
| CREATED BY : Meyers, Jeffrey (07/28/2016 3:00)
*------------------------------------------------------------------*
| VERSION UPDATES:
| 2.46 11/03/2021
| Changed code to avoid truncating character strings at 200
| 2.45 08/25/2021
@statgeek
statgeek / SAS_unzip_copy_extract_xpt.sas
Created November 10, 2023 21:28
SAS - Read a zipped xpt file into SAS
*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)
@statgeek
statgeek / SAS_fmtsearch_demonstration
Created October 7, 2022 20:03
Example of FMTSEARCH option usage in SAS
/*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'
@statgeek
statgeek / SAS_moving_stats_monthly
Created February 26, 2022 03:01
SAS - moving statistics monthly
/*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;
@statgeek
statgeek / SAS_split_export.sas
Created February 16, 2022 16:22
SAS - export to SAS and split file by number of records or size of data set
*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;
@statgeek
statgeek / SAS_create_format_other_freq.sas
Created December 15, 2021 01:55
Create an Other Category automatically within PROC FREQ
/*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;
@statgeek
statgeek / SAS_merge_groupformat.sas
Last active November 5, 2021 16:20
SAS - merge with formatted data
*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;