sha256
stringlengths
64
64
language
stringclasses
27 values
size
int32
1
491k
lines
int32
1
21.8k
content
stringlengths
1
200k
7785c79618c010fc405e3aec4334441874e66193737cd4f0e4cb3edb3374ecfc
SAS
949
62
%macro AddRowNumber4Com_Vars(dsdin,Com_Vars,desending_or_not,dsdout); %let vars=%sysfunc(prxchange(s/ +/%str(,)/,-1,&Com_Vars)); %put Your input Com_Vars are &vars; proc sort data=&dsdin; by &Com_Vars; run; data &dsdout(drop=tag); length tag $200; retain tag '' ord 0; set &dsdin; if _n_=1 then do; tag...
b6c5fc1c991a975ce05e22a9dc201863c7902973b201477c57cf4c26cf4c25db
SAS
949
48
%macro make_dbsnp_db( dbsnp_fullpath, outlib_path, outdsd ); libname O "&outlib_path"; %File_Head(filename="&dbsnp_fullpath",n=10); %ImportFilebyScanAtSpecCols(file=&dbsnp_fullpath ,dsdout=O.&outdsd ,firstobs=1 ,dlm='09'x ,ImportAllinC...
8bb50057c762a3725a0563335688b5bd68acaff9835f9dfb4114f5981c54fbdb
SAS
962
30
/* MACRO %GetVarType --> Calls %GetVarAttrib with specific parameter values Version: 1.03 Author: Daniel Mastropietro Created: 18-Nov-2004 Modified: 24-May-2015 (added vartype as LOCAL variable!, previous: 07-Jun-2012) DESCRIPTION: Returns the type (character or numeric) of a given variable in a dataset...
93dd9b14e42eacda926f391408881994d5b512dd73f721ef792f2dcda0287a5f
SAS
975
39
%macro list_files(dir,file_rgx); %local filrf rc did memcnt name i; %let rc=%sysfunc(filename(filrf,&dir)); %let did=%sysfunc(dopen(&filrf)); %if &did eq 0 %then %do; %put Directory &dir cannot be open or does not exist; %return; %end; %do i = 1 %to %sysfunc(dnum(&did)); %let name=%...
0caa1903323b46ece83529ad7263d8e5c50e6939934f487877d8ae4007fb6731
SAS
977
40
%macro replacestrinfile(file,strrgx,newstr4rep,casesensitive=0,outdir=,outprefix=modified.,firstobs=1,obs=max); filename IN "&file"; %if "&outdir"="" %then %do; %let outdir=%curdir; /* %let outdir=%sysfunc(getoption(work));*/ %end; filename OUT "&outdir/&outprefix.&file"; data _null_; ...
bdc747a74752866b9e702704b30eb67a835597612b5546a90625de5198b11c82
SAS
992
41
%macro AddNullData2SeparateDsd(dsd,FrtSrtVar,SecSrtVar,Num4AddedNullLines,AddVar4output,Value4AddVar,dsdout); proc sort data=&dsd;by &FrtSrtVar &SecSrtVar; data &dsdout; set &dsd; if not last.&FrtSrtVar then output; else do; do i=1 to &Num4AddedNullLines; if i=1 then output; else do; &AddVar4output=&Value4AddVa...
fef2021dc20ef06a1e9263c6e033f1cff4a33d890e98be254fd2bdf719fb3aca
SAS
1,009
55
%macro number_rows_by_grp( dsdin, grp_var, num_var4sort, descending_or_not, dsdout ); %if &descending_or_not %then %do; proc sort data=&dsdin; key &grp_var &num_var4sort/ descending; run; %end; %else %do; proc sort data=&dsdin; key &grp_var &num_var4sort; run; %end; proc sort data=&dsdin;by &grp_va...
1a0378552a5dbe8887595b68dda2b3906d38939a29109aadcae2bb134410d829
SAS
1,019
30
%macro get_filenames(location=,dsd_out=filenames,match_rgx=); filename _dir_ "%bquote(&location.)"; data &dsd_out(keep=memname); length memname $1000.; handle=dopen( '_dir_' ); if handle > 0 then do; count=dnum(handle); do i=1 to count; ...
d081886e1177a99281aee73435b03a193616bbd56454e6c2e76f894b4b5dce0f
SAS
1,021
49
/* Apply variable names, labels and formats from dataset indsd to target_dsd */ *options mprint; %macro App_Dsd_Lbl_Fmt_To_Other_Dsd(indsd,target_dsd); %let dsd_name=%scan(&indsd,-1,'.'); %let dsd_lib=%scan(&indsd,-2,'.'); proc sql noprint; create table temp as select name,label,format from dictionary.colum...
bd1bcfa9a2baca7796648ff0ad5b1d84d07c291f5d21a9f02046b210a2841e99
SAS
1,022
43
%macro protein_coding_genes_close2gene( gtf=gtf_hg38, chr4gene=2, dist=1e6, genesymbol=SF3B1, outdsd=combined_genes_by_dist, macrvar4genes=nearby_genes /*Create a macro var to save these genes separated by space*/ ); %global &macrvar4genes; data input; set &gtf; where chr=&chr4gene and ensembl_transcript con...
e5d0df68ba49325ecd697c11cb3184c48ff15659b5cf42a6927b965c49f0c8a4
SAS
1,022
36
%macro import_all_bims( dirpath=., outdsd=all_bims, debug=0 ); %get_filenames(location=&dirpath,match_rgx=bim); data &outdsd (drop=fname filepath memname t); set filenames; filepath = "&dirpath"||"\"||memname; *Need to add truncover to infile data successfully; %if &debug=1 %then %do; infile dummy ...
1e67f6d78d48129786021fe34e13ce86c10bc9f3c3d501abb563f5f4f389f85a
SAS
1,032
61
%macro QueryInterVar4MultVars( query_dsd=, chr_var=,/*chr var in numeric notation*/ pos_var=, ref_var=, alt_var=, build=hg38, dsdout=results4allvars ); data _null_; set &query_dsd; n=_n_; rc=dosubl('%QueryInterVar(chr='||&chr_var||',pos='||&pos_var|| ',ref='||&ref_var||',alt='||&alt_var||',build='||"&build"|| ',dsdout...
52861e7a07f4928ce6e23c2214d92538496206ffc50874c1bf593b7f1ceb6680
SAS
1,042
36
%macro print_text_as_title( text=%str(Put your text here to print.) ); proc odstext; p "&text" /style=[color=darkred fontsize=14pt just=center fontfamily=arial]; run; *The following codes do not work very well; /* data _tmp_; */ /* length _line_ $32767; */ /* _line_="&text"; */ /* output; */ /* pro...
d4b847ee029117be0146d2ddee158893af2770e74b2c6054ca866ecd59cd7e0b
SAS
1,045
61
%macro fmt_num_with_char(dsdin,numvar4fmt,charvar4fmt,fmt_output_name); /* *No need this; proc freq data=&dsdin; table &var4fmt/noprint out=uniquevalues; run; */ proc sort data=&dsdin out=uniquevalues nodupkeys; by &numvar4fmt; run; data fmtdsd; set uniquevalues; retain fmtname "&fmt_output_name" type '...
37bd9d00aa45c3f69e86171dc2c402de0022ba108782ad5e412c6d6e0e3cfe5e
SAS
1,054
39
%macro RandBetween(min, max); %local min max rnd _unif_num_ _rnd_; %let _unif_num_=%sysfunc(ranuni(0)); %let _rnd_=%sysevalf((1+&max-&min)*&_unif_num_); %let rnd=%sysfunc(floor(&_rnd_)); &rnd %mend; /*Demo codes:; *Note: rand('norma') does not work when using the macro by other macro!; *So the macro has ...
a1e2caae8813337f8f39567ee2456b5a51e3157e74ac425089495472f9c0cc0a
SAS
1,063
42
%macro SplitDsdIntoMultiDsdsByNumGrp(dsd,numgrpvar,newdsd_prefix); %local grp_var_list ii; proc sql noprint; select distinct &numgrpvar into: grp_var_list separated by ' ' from &dsd; %put group vars: &grp_var_list; *Do not use macro var i here, as it was used by Rename_Add_Prefix4All_Vars; *Which...
7b0f8b4bfa68b13e99a2e08b915bea11bf307e052f7269ac5106568d978b2971
SAS
1,064
74
%macro chr_format_exchanger(dsdin,char2num,chr_var,dsdout); data &dsdout(drop=_chr_); set &dsdin(rename=(&chr_var=_chr_)); %if &char2num %then %do; if lowcase(_chr_) in ("chrx","x") then do; &chr_var=23; end; else if lowcase(_chr_) in ("chry","y") then do; &chr_var=24; end; else do; /* ...
d6adc3fdeba33c7760db29d6c582efa8dab247e69967b49faf3bc875a3db787e
SAS
1,075
47
/* Apply variable names, labels and formats from dataset indsd to target_dsd */ *options mprint; %macro KeepColNotMatchingRgx(indsd,Rgx,outdsd); %let dsd_name=%scan(&indsd,-1,'.'); %let dsd_lib=%scan(&indsd,-2,'.'); proc sql noprint; create table temp as select name,label,format from dictionary.columns w...
7df39a6cf775af0427603388c50c07956a174565ce1c2052701384f072dc29ba
SAS
1,076
33
%macro varexist /*---------------------------------------------------------------------- Check for the existence of a specified variable. ----------------------------------------------------------------------*/ (ds= /* Data set name */ ,var= /* Variable name */); /*---------------------------------...
764ffee398f784fd86a686e8a59c808f0c1cf491010244a300d13e5f011425bb
SAS
1,078
42
%macro AddSpaces4str(str=test_str,add2end=1,nspaces=3,char4space=-); %local _ns_ _str_; %let _str_=&str; %do _ns_=1 %to &nspaces; %if &add2end=1 %then %do; %let _str_=&_str_%str(&char4space); %end; %else %do; %let _str_=%str(&char4space)&_str_; %end; %if &_ns_=&nspaces %then %do; &_str_...
422a955e0618eaacfc1b6be6be4f33d476fe27756744c63e79244c6ae2632c4f
SAS
1,079
43
%macro bed_regions_plot(indata=, yvar=, groupvar=name, startvar=start, endvar=end, linesize=10); data bed_regions; set &indata.; length pos 8; array p{*} &startvar. &endvar.; do i = 1 to 2; pos = p{i}; output; end; drop i; run; ...
b39d901dd563078f92abf8092cb8fb8bdfed2ed6af8cdfe7d5dc9e535500ad7f
SAS
1,086
40
%macro iml_PrintDescStats(table); %local lib dsd; %if %index(&table,.) %then %do; %let lib=%scan(&table,1,.); %let dsd=%scan(&table,2.); %end; %else %do; %let lib=work; %let dsd=&table; %end; proc iml; start PrintDescStats( tbl ); cols = loc( TableIsVarNumeric(tbl) ); /* get column numbers */ if ncol(cols)=0 then ...
2fa5b1c8324304c1e6e33e87c6a634f73869592afdcf608b7a20037dcfc807c4
SAS
1,097
42
%macro QueryLD_SNPs_at_Haploreg4( snp=rs2564978, LDpop=EUR, ldThresh=0.7, outdsd=LD_dsd ); %let query_str=%nrstr(&query=)&snp%nrstr(&ldThresh=)&ldThresh%nrstr(&ldPop=)&LDpop%nrstr(&output=text&submit=submit); *Note: the important ldPop is required to obtain all high LD SNPs for the query SNPs; *If no ldPop provided, it...
ccac2ccae3a0c3ecd23f773c488643a442cf4c9860c41b50e8b5d8d5fc149d9d
SAS
1,098
41
%macro regress_out_covar_effects( dsdin=,/*Input dsd*/ dsdout=,/*output dsd*/ varadjlist=,/*char covars used to adjust effects; these char covars are required to be put into the class statment*/ modeladjlist=,/*all covars, including char and numeric covars in a format for the model statment of proc glm; ensure the ...
430466a5c165966862c383ce821e9c2196a01165f9c47db53a30272921c39fcb
SAS
1,099
38
/*An alternative way to create new directory; %macro Create_Dir(dir=) ; options noxwait; %local rc fileref ; %let rc = %sysfunc(filename(fileref,&dir)) ; %if %sysfunc(fexist(&fileref)) %then %put NOTE: The directory "&dir" exists ; %else %do ; %sysexec md &dir ; ...
d8d2648a3adfa002920c5109db0a164a1b9ce3db3446dd637f5e4869f2ae950b
SAS
1,099
47
%macro Check_VarnamesInDsd(indsd=,Rgx=.,exist_tag=); %global &exist_tag; %let &exist_tag=; %put Your input sas dsd is &indsd; *Add quit here to quit process that may prevent the script from running proc contents; quit; %put Going to run proc contents to obtain variable list!; proc contents data=&indsd out=_t...
404787dd151619aecec8a8e9af67964b534bd5d801c3eefb919a66e07039dd98
SAS
1,100
38
%macro tabulate4bins(dsd,byids,target_var4bin,bins,dsdout); %let ncutoffs=%numargs(&bins); /*change byids for proc sql;*/ %let _byids_=%sysfunc(prxchange(s/\s+/%str(,)/,-1,&byids)); %let i=1; %let bin=%scan(&bins,&i,%str(' ')); %let i=2; %let format_string=%sysfunc(cat(low-,&bin)) = "low>=&bin"; %put &format_st...
9cccb29b53f5e2cc1eb7c53dd16f0c45ad9eecb2221a19041533023ee2383bca
SAS
1,103
32
%macro keep_uniq_lst( name,/*macro variable name that will be created to include the unique elements in the input variable lst note: for duplicates, the last element will be kept in the final macro var!*/ lst /*Input list containing duplicates or multiple spaces; note: spaces will be trimed!*/ ); *Need to asign t...
1809ebc3ece3586ae2c87f1f51ef1d1c943146f808252c953be2f6c0666fa3a1
SAS
1,106
29
%macro FileAttribs(filename); %local rc fid fidc Bytes CreateDT ModifyDT; %let rc=%sysfunc(filename(onefile,&filename)); %let fid=%sysfunc(fopen(&onefile)); %if &fid ne 0 %then %do; %let Bytes=%sysfunc(finfo(&fid,File Size (bytes))); %let CreateDT=%sysfunc(finfo(&fid,Create Time))...
66e0d988d95a7537b3c82698719706631a0df8ba4f5ffcfe14592ced8fdc649b
SAS
1,106
43
%macro Remove_dups_in_dsd(dsd,sort_var,key_var,first_or_last4dup,dsdout,sort_var_cutoff_func); /*sort the values of sort_var and keep all structure with the first or last unique*/ /*values of key_var;*/ /*first_or_last=1 will keep first unique value that sorted ascendingly */ /*first_or_last=0 will keep last unique...
98a88496c98e302495cad6906f36b3e56c1536d411d9732fc897ebee2cae5e5a
SAS
1,107
47
%macro rename_files_in_dsd(dsd,filevar,indir,newfilevar); *Remove duplicates in newfilevar; proc sort data=&dsd nodupkeys; by &newfilevar; run; proc sql noprint; select count(&filevar) into: n from &dsd; proc sql noprint; select &filevar into:v1-:v%sysfunc(left(&n)) from &dsd; proc sql noprint...
3b29dac9da786019eba16e817ae405b3bfa62d212c8e3dbf28282f018682a0e8
SAS
1,115
35
%macro dwn_http_file(httpfile_url,outfile,outdir); %if "&outfile"="" %then %do; %let outfile=%sysfunc(prxchange(s/.*\///,-1,&httpfile_url)); %end; %if "&outdir"="" %then %do; *%let outdir=%curdir; %let outdir=%sysfunc(getoption(work)); %end; %put Downloaded file will be put into here:; %put &outdir/&outfile; filename o...
89a2d67b59ff0e1213a21189296a6ee05b1135295f9ff46e491fc4b7521bc506
SAS
1,125
49
%macro Query_GTEx_eQTLs4Genesymbol( ensembl_gene_id=ENSG00000128383.12,/*For Apobec3a*/ outdsd=gene_eqtls ); *https://gtexportal.org/api/v2/redoc#tag/Static-Association-Endpoints/operation/get_significant_single_tissue_eqtls_api_v2_association_singleTissueEqtl_get; *for Apobec3a: ENSG00000128383.12; %let url_link=%str...
4e37b547e3db4d597cde1bcf59fd90bdcf2e5e085b73164e5923f53fde39a135
SAS
1,129
33
%macro FileOrDirExist(dir) ; %LOCAL rc fileref return; %*arbitrarily assign value 0 to output if dir is empty; %*This will avoid of error message issued by fexist later; %if %length(&dir)=0 %then %do; 0 %end; %*It is necessary to add else do macro statement here, otherwise, even if...
a06f0338548f257168ec97cc3107cef69982f1632185547d35069903dbbf27f9
SAS
1,134
54
%macro get_nearby_genes_by_dist( gtf,/*GTF sas data set generated by the macro get_genecode_gtf_data*/ dist=5e4, outputdsd=combined_genes_by_dist, output_cnts4genes=gene_cnts, max_gene_cnts4histgram=100 ); data gtf_hg38; set &gtf; run; data gtf_hg38; set gtf_hg38; where type="gene"; keep genesymbol chr st ...
310bdce65906852b6a9182aacd9ac055004944da7922e74075c756014c276c0e
SAS
1,148
51
%macro RunMacrosRepeatedly(Mvar_dsd,Mvar,MacroFullCommand); proc sql noprint; select count(unique(&Mvar)) into: tot from &Mvar_dsd; select unique(&Mvar) into: v1 -: %sysfunc(catx(%str(),v,&tot)) from &Mvar_dsd; %do i=1 %to &tot; %put &&v&i; %let RepeatVar=&&v&i; %str( data _null_; ...
a24f3a516672bb255902fbf9ec15cb9241b8cc4514fddfad4564a37cbd256952
SAS
1,156
39
/* Here is another version of David's macro. It eliminates the need to place surrounding symbols around the list. Some may see this as advantage, while others may think it a disadvantage. It also allows the separator to be any of the standard ones accepted by SCAN and used in a legal manner ( i.e. no use of 1(2...
1430bf9eaffba4213220c64f93338f08e1783c6a0f0a0e0cd5d130d5b50d362f
SAS
1,162
38
%macro Union_Selected_Data_In_Lib(lib,excluded,dsd_not_contain_rgx,dsdout); %let re=%sysfunc(prxparse(s/ /" "/oi)); %let rm_list=%sysfunc(prxchange(&re,-1,&excluded)); %let n_rgx=%eval(%sysfunc(count(&dsd_not_contain_rgx,%str( )))+1); %syscall prxfree(re); /*default memname char(32), which may be too short*/ proc...
64ef5f5206a8579ee3c7513332246683fa92d9617848a604c50558c5cb3a4388
SAS
1,171
51
%macro GetZIPContents(zip,dsdout); *this script is only able to get contents of ZIP but not gzip; *as gzip can not be opened directly!; %let rc=1; filename inzip ZIP "&zip"; /* Read the "members" (files) from the ZIP file */ data &dsdout(keep=memname isFolder); length memname dirname $500 isFolder 8; fid=dopen("inzip...
06211980a634bb5f457840e433a78beff11667c12b8dfc79bb10e598d5196d7a
SAS
1,172
60
%macro Zscore4matrix(dsdin ,rowwide ,ByVar4rowwide ,dsdout ); %if %eval(&rowwide=0) %then %do; /*colwide z-score*/ proc standard data=&dsdin mean=0 std=1 out=&dsdout; var _numeric_; run; %end; %else %do; /*row-wide z-score*/ proc transpose data=&dsdin out=&dsdin._tmp; var _numeric_; by &ByVar4rowwide n...
6a175511f06efe6ffc42a1f8c4f486bb4088c7a35b7dd609297c4947ef96ed74
SAS
1,172
41
*Note: if sep=%str(,), the macro var list needs to be bquoted!; %macro select_element_range_from_list( list=, st=1, end=, /*If empty, the total number of elements will be used by it*/ sublist=sublist,/*Output a global macro variable for using by other SAS codes*/ sep=\s /*Perl regular expression for target separ...
b2519789067e10abf900692bc291d5f2d7c65879cef3e83e888e4f6cb0fc8f62
SAS
1,173
41
%macro longdsd2matlabmatrix(dsd,var_row,var_col,data_var,value2asign4missing,dsdout,outdir4matrix); proc sort data=&dsd;by &var_row &var_col; proc transpose data=&dsd out=&dsdout(drop=_name_); var &data_var; by &var_row; id &var_col; run; data &dsdout; set &dsdout; array x{*} _numeric_; do i=1 to dim(x); ...
172271883dfb18fd317a665102d4299195ae101642b9b6ee7db8a927bb3dd5a1
SAS
1,176
45
%macro Bed2SAS_DB(Bed_Dir,Regex4bed,Libname4out,outdsd); %ImportAllFilesInDirbyScan(filedir=&Bed_Dir ,fileRegexp=&Regex4bed ,dsdout=reg_dsd ,firstobs=0 ,dlm='09'x ,ImportAllinChar=1 ,MissingSymb=NaN ...
6ce45ff5ec65ad3f4ee5d290b0bdb254e87a8c1421969d68bab29ddc5a87be70
SAS
1,176
41
%macro ParseEnrichedGenesFromWebgestalt(enrichment_file,dsdout); *typical Webgestalt file: enrichment_results_wg_result1642738253.txt; proc import datafile="&enrichment_file" dbms=tab out=&dsdout replace; getnames=yes; guessingrows=1000; run; data &dsdout (keep=gene description FDR); *use strict FDR < 0.01; ...
345c58296f2758b96ff26b5adaaae1844c1451d4eabedce2aebc232bedc920ea
SAS
1,182
38
%macro have_dups4var( dsdin=, var=, dup_indicator= ,/*A name for a global macr var to indicate whether there are dups in var, the value of which will be 1 or 0*/ dupdsdout=dups,/*A sas dataset containing exisiting duplicates*/ nodupdsdout=nodups /*A sas dataset containing non-duplicates*/ ); %global &dup_indic...
132ed19419ac4e705ed8ce9024f53d982d8bac75a43118c07e309d37b2689102
SAS
1,191
42
%macro curdir; /*---------------------------------------------------------------------- Returns the current SAS directory physical name. ----------------------------------------------------------------------*/ /*---------------------------------------------------------------------- Originally developed by Tom Hoff...
66c2661f62b313de50a7b16473d01d4c4a018250335b1b9b3c16e4c3b3472702
SAS
1,192
50
%macro Scaleup_nrow_ncol(dsdin,row_var4row,row_var4col,value_var,dsdout); %if "&value_var"="" %then %do; %let value_var=*; %end; data tmp; set &dsdin; proc sort data=tmp nodupkeys; by &row_var4row &row_var4col; run; /*Important to get unique values for row and col individually*/ proc sql; create table t...
1810dd0ab78abf46eb8bd711bb3e77f13110d2315f7c3da7ebca690b09bf57ff
SAS
1,198
36
%macro parse_macro_used_macros(macro_filepath,dsdout); data &dsdout; retain macro_i 0; length file $1000. Macro_Info $1000.; infile "&macro_filepath" lrecl=10000 obs=max; input; Macro_Info=_infile_; x=Macro_info; *It is important to stop the processing when encounter these Demo codes; if prxmatch("/Demo/i",M...
1b1792d06f4cc4c0250c22c7f4a8dc2efeae5bafb69d522e006089ac5ee81fff
SAS
1,218
57
%macro calc_pairwise_LD_among_1KG_pops( snp1=, snp2=, outdsd=out, pop=GBR /*Provide one population of the 1000 Genome phase 3 populations: CHB, CEU, ...; if empty, it will query all populations and calcuate pairwise LD;*/ ); filename G temp; %if %length(&pop)>0 %then %do; *Query in one population; %let ...
d2d0ba939865b53e683a87406a74747fccbd118669791a05d242ea4909a75eb8
SAS
1,241
46
%Macro Import_Space_Separated_File(abs_filename,firstobs,getnames,outdsd); filename outfile "tempdata.txt"; data _null_; retain n 0; infile "&abs_filename" lrecl=32767 firstobs=&firstobs end=end; file outfile; input; _infile_=strip(_infile_); _infile_=prxchange("s/\bNA\b/./",-1,_infile_); _infile_=compbl(_in...
91a61633ab3d843543be7487a3e4ff714ffa6f4ec43728d1a7ff33d7b8be7308
SAS
1,245
45
/*%let sysparm = name1=value1,name2=value2,name3=value3 ;*/ /* Accepts multiple name value pairs e.g -sysparm ‘name1=value1,name2=value2’ N.B.: &name1 &name2 are %global sysparm must be put at the end of command; */ %macro multi_sysparm; data _null_; length sysparm express param value $ 200; sys...
5eeaae3bd59d45e8a7841ed8f2c3a8cabaaf7fc2e4b17af8e229b7e3b5841967
SAS
1,246
59
%macro random_subset_cols4dsd( dsdin, rgx2matchcols, rgx2fixedcols, rnd_pct, dsdout ); proc contents data=&dsdin out=sampling noprint; run; *get fixed column names and saved them into a macro var; *These fixed columns usually are few, so the length of macro var will not be truncated; proc sql noprint; select name int...
2e78bab2e4580f947a49b1913ef0887309e1ef1efdfd84632d2d2836377e99df
SAS
1,248
61
%macro rename_sas_dsd( dsdin, dsdout ); *rename the &dsdin as &dsdout; %if %index(&dsdin,.) %then %do; %let _dsdin_=%scan(&dsdin,2,.); %let _inlib_=%scan(&dsdin,1,.); %end; %else %do; %let _dsdin_=&dsdin; %let _inlib_=work; %end; %if %index(&dsdout,.) %then %do; %let _dsdout_=%scan(&dsdout,2...
52c6bb5b4ab2ca761d7dc8530d72a645220721be4e075aa6b067424f948145ec
SAS
1,248
49
%macro boxgrpdisplaysetting( boxwidth=0.8, by_cluster=1 /*If boxplots are not plotted in sgpanel by subgrps, such proc sgplot, please provide value 0 to draw boxplot not in cluster*/ ); %if &by_cluster=1 %then %do; %str( groupdisplay=cluster boxwidth=&boxwidth fillattrs=(transparency=0.5) whiskerattrs=(patter...
465d09606a40e2434290cb31201964941d611c71a803f5f97113d13c26d457f0
SAS
1,256
56
/* Apply variable names, labels and formats from dataset indsd to target_dsd */ *options mprint; %macro KeepColMatchingRgx(indsd,Rgx,outdsd,insensitive); %let dsd_name=%scan(&indsd,-1,'.'); %let dsd_lib=%scan(&indsd,-2,'.'); %if (&insensitive eq 1) %then %do; %put Rgx will be case insensitive; %let Rgexp=/&rg...
d79ac03bb8a2e36829a761151e8fa87c7bcf4dcc83137a36d2d766c28c9313fe
SAS
1,275
45
%macro filter_longform_dsd4matrix( dsdin=, var4matrix_row=, /*target variable that will be put into row-wide for a matrix*/ var4matrix_col=, /*target variable that will be put into column-wide for a matrix*/ value_var4matrix=, /*Numeric value variable for filtering*/ value_cutoff_fun=min,/*SQL group functions...
b6ce048105e0d47eb5c4e0d0cc5152820b94f59dd0ec5f4753a13ef7cf8f8195
SAS
1,283
39
%macro gnomad4proteinpaint(dir4gnomadcsv,gnomadcsv); x cd "&dir4gnomadcsv"; %let gnomad_file=&gnomadcsv; proc import datafile="&gnomad_file" dbms=csv out=gnomad replace; getnames=yes;guessingrows=10000; run; data out(keep=chr Protein_st Vtype); length chr $100.; set gnomad; chr=compress(catx(":",catx("","chr",...
49c62973203aec2e885429347f774bd47cbdca9a4eeb2e898214481e3646c185
SAS
1,286
52
%macro listfiles2dsdInUE(dir,filergx,outdsd); *Change dir into macro dir; data _null_; rc=dlgcdir("&dir"); put rc=; run; *For UE; *%include "/folders/myshortcuts/zcheng/Macros/list_files.sas"; *%include "/folders/myshortcuts/zcheng/Macros/del_file_with_fullpath.sas"; *For SAS onDemand; *%let uedir=%sysfu...
1bc420e88d87eed5f4c1fa532a23095ecda15e5950aa6706d2bbb0ffae6d5958
SAS
1,295
45
%macro Merge_Dsd_In_Lib_Rgx(lib,excluded,dsd_contain_rgx,comm_vars_rgx,dsdout); %let n_rgx=%eval(%sysfunc(count(&dsd_contain_rgx,%str( )))+1); /*default memname char(32), which may be too short*/ proc sql noprint; create table temp_xyz as select * from dictionary.tables where libname=upper("&lib"); %if "&e...
58a8c28ae7166ca21d16d8f449ef6c40aa283ef9d486ff517e3f5613355b486a
SAS
1,299
49
%macro Import_VCF(dir=,filename=,dsdout=); options compress=yes; filename vcf "&dir/&filename"; *Get the total number of header lines; *The last header line is used as header in proc import; data _null_; infile vcf lrecl=32767 length=linelen; input header $varying32767.linelen; n=_n_; if substr(header,1,1)="...
e41b1e37cfd95d9c026197634ffefde521a9010a1ad7fea0f4a51f5b61996dd8
SAS
1,299
45
%macro Union_Data_In_Lib_Rgx(lib,excluded,dsd_contain_rgx,dsdout); *Asign fake value to exclude dsd if the var excluded is empty; %if %length(&excluded)=0 %then %let excluded=_____________; %let n_rgx=%eval(%sysfunc(count(&dsd_contain_rgx,%str( )))+1); /* %syscall prxfree(re); */ /*default memname char(32), which may...
2fe6f0462e57114e96a38ab2ea204091fef89faaa22a3d3acbc8e21f997202df
SAS
1,304
61
%macro cp_files_in_dsd(dsd,filevar,indir,outdir,newfiletag); proc sql noprint; select count(&filevar) into: n from &dsd; proc sql noprint; select unique(&filevar) into:v1-:v%sysfunc(left(&n)) from &dsd; %if (&newfiletag ne and &indir eq &outdir) %then %do; %do i=1 %to &n; %cp(f=&&v&i,fdir=&indir...
776cd086592ed2bde0d6d1427934b7ecc139d7bcd3d92168692ff48d4059082f
SAS
1,310
48
%macro Query_Large_File_With_Idx(idx_var,rownames,dsdin,dsdout); options nonotes nosource; %put Query_Large_File_With_Idx(idx_var,rownames,dsdin,dsdout); %put 'Query rownames are: ' &rownames; %let num=1; %let rowname=%qscan(&rownames,&num,%str( )); %do %while(&rowname ne); %if (&num=1) %then %do; /* Pay atten...
59d54076618f9612ae838c8acb445b0dbf17f12d6f891614ff6bcc6ed28435ba
SAS
1,318
58
/* Apply variable names, labels and formats from dataset indsd to target_dsd */ *options mprint; %macro Rename_Del_Rgx4All_Vars(indsd,Rgx); %let dsd_name=%scan(&indsd,-1,'.'); %let dsd_lib=%scan(&indsd,-2,'.'); proc sql noprint; create table temp as select name,label,format from dictionary.columns where ...
beeb6b34aed1e8892793db74204a3ec126293161b777c0bd5b1a11204d274433
SAS
1,329
58
%macro cp(f,fdir,out,outdir); %let filrf=myfile; %let rc=%sysfunc(filename(filrf, &fdir\&f)); %let cpfileref=myfilecp; %let rc1=%sysfunc(filename(cpfileref,&outdir\&out)); %let fid=%sysfunc(fcopy(&filrf,&cpfileref)); %put &fid; %if &fid=0 %then %do; %put "copy it successfully for" &fdir\&f ", which is saved ...
b294922ccf57f32aa82336ac9fab3c29187848143d25501c82727a749cf66314
SAS
1,333
44
%macro ImportDsd_via_Proc_Import(filepath, _kept_variables, _getnames_yes_no, _datarow, _dbms, _force2Num, dsdout); *Make Linux and WIN usable filedir; %let filepath=%sysfunc(prxchange(s/\\/\//,-1,&filepa...
0d6f052c3d942b0c9ef86d320a86d2bfd12a3ca93ecf468cac68f694d2e5eb62
SAS
1,334
60
%macro allele_columns2geno( dsd=, cols4alleles=4-9,/*Use %bquote if containing comma among these column numbers!*/ outdsd=out ); %pull_column(dsd=&dsd,dsdout=&outdsd,cols2pull=&cols4alleles); *get other columns not matching with these pulled columns; %pull_column(dsd=&dsd,dsdout=&outdsd._,cols2pull=&cols4alleles...
fb29c55f063e823b83e90fbc9aabec104e30a9c440eb38457400a7f46deb884a
SAS
1,339
55
%macro pull_column(dsd,dsdout,cols2pull,exclude_pulled_cols=0); %check_col_orders(dsd=&dsd,colorder_info_out=colinfo,print_colobs=0); proc sql noprint; select count(*) into: tot from colinfo; select NAME into: v1 - : v%sysfunc(left(&tot)) from colinfo; *replace numbers with linker to consective numbers; ...
99fee910f1dfea7935c7c7e4c76997914699fbf571b9a2ccc12b506c287df90c
SAS
1,349
44
%macro scale_nums_in_list(/*Note that the input list with or without double quotes should be delimited by space*/ list, factor, contain_double_quote=1 ); %local _list_ _a_; %*remove double quotes if there; %if &contain_double_quote=1 %then %do; %let list=%qsysfunc(prxchange(s/" "/ /,-1,&list)); %let list=%...
a7a5b3125d0cb7abe2c9708a901c3ecd4ed61c79d03e6b0adad05db1f509dc57
SAS
1,351
40
%macro squeez_single_num_var_length( dsdin, /*Note: the var in the dsdin will be squeezed, which means the output dsd would be dsdin*/ var); %put going to reduce dsd size by using length command; %let size=%FileAttribs(%sysfunc(getoption(work))/&dsdin..sas7bdat); %put unreduced dsd size is &size Mb; data _null_;...
9ef344a91ef4036d260208351bab0302d808954eb2d65842eaf9523127ead458
SAS
1,360
73
%macro GetNumGeno4VCF( vcf_file=, dsdout=NumGeno ); *Get the total number of header lines; %Header4VCF( vcf_file=&vcf_file, global_header_num=vcf_header_num, global_colnames=vcf_colnames, global_vcfcolnums=vcfcolnums ); filename g "&vcf_file"; %let numofsample=%sysevalf(&vcfcolnums-9); data &dsdout...
481e03cbfe916e1e0e4e701d07f6c7a0edf58e121f577eb679f117e2de6fa0f8
SAS
1,361
55
%macro import_fasta_like_file( fasta_like_file,/*A file contain data like that of fasta*/ header_start_char,/*regular expression to match the start chars*/ outdsd, onelinemode=1 ); /*clear and create new temp file*/ /*filename FT15F001 clear;*/ filename FT15F001 "&fasta_like_file"; /*Import data using parmcard...
bf31429bdf11f216d5303834d533887ab4afb7998f7228630212831e93439c88
SAS
1,368
49
%macro Rename_vars_with_info_from_dsd( dsdin, var_info_dsd, old_var_info,/*a variable containing old variable names in the dsd var_info_dsd*/ new_var_info,/*a variable containing new variable names for renaming the old variable names in the dsd var_info_dsd*/ outdsd); proc sql noprint; select &old_var_info,&n...
5e684073e4e7b7a4deedae2a15586c41162344380ddd3bd28da8560e33ee3db9
SAS
1,375
52
/* Apply variable names, labels and formats from dataset indsd to target_dsd */ *options mprint; %macro Rename_Add_Prefix4All_Vars(indsd,prefix); *The macro requires to have the input dataset in the format of lib.dsd; %if %index(&indsd,.) =0 %then %let indsd=work.&indsd; %put your input dataset is assumed as &ind...
64079a50a98ef33e8cb3b5fccfd4b709380713cb40b443e7d79c80ff2fdf8fa7
SAS
1,384
60
%macro tanspose_table( indsd=, /*A table with unique rownames and multiple variables for transposing into row-wide*/ rowname_var=,/*a variable name in the input data set to be transposed into column-wide; Only unique rownames will be kept for transposing*/ column_vars=_numeric_,/*A list of variables that are subjec...
bdec990c3cba12f7718f9b97cb5ed240ef230aa7fae284728b052944e342b4da
SAS
1,394
41
/* data spambase; %let url=//archive.ics.uci.edu/ml/machine-learning-databases; infile "http:&url/spambase/spambase.data" device=url delimiter=','; input wf_make wf_adress wf_all wf_3d wf_our wf_over wf_remove wf_internet wf_order wf_mail wf_receive wf_will wf_peo...
3c4e407aaab1c7fdfd86ed94447b62acfb6f9ec57ce89a1f79eccb6c0f69b2cc
SAS
1,398
68
%macro longdsd2struct_dsd( indsd, key1st_var, key2nd_var, structdsdout, max_iteration=100 /*the number of times to recursively perform proc sql to lookup these keys*/ ); *remove duplicates and two keys are the same records; proc sort data=&indsd(where=(&key1st_var^=&key2nd_var)) nodupkeys; by &key1st_var &ke...
5f5cce5f354c3163cf3930696fd7296ef4c0ed76590e4e464b713a3d9b2c9317
SAS
1,412
57
%macro ImportGeneLevelASE(filenames,dsdout,Reads4AB); *Read cutoff of two haplotypes; %if &Reads4AB eq %then %do; %let Reads4AB=20; %end; %let i=1; %let fn=%qscan(&filenames,&i,%str( )); %do %while (%qscan(&filenames,&i,%str( )) ne); /*%let outdsd=%sysfunc(prxchange(s/\-/_/,999,&fn));*/ %ImportFilebyScan(fi...
cbcf12e6c9dae76c380f8d631a34961eaace763a4406c6ba1c02a52c10e59747
SAS
1,432
78
%macro groupsummary( dsdin, grps,/*grps for the by statement*/ vars4summary,/*Numeric vars subject to input functions by group*/ funcs4var, /*functions exclusively for the proc means*/ dsdout, include_org_dsd_in_output=1 /*add the input dsdin into the dsdout*/ ); proc sort data=&dsdin; by &grps; ods selec...
ce01552c034140229cba2bd7a92dfb9243ef8e64e5f19d2c4e79ea612628576b
SAS
1,450
46
%macro union(dsn1=, /*Name of the first data set */ dsn2=, /*Name of the second data set */ out= /*Name of combined data set */); proc contents data=&dsn1 noprint out=out1(keep=name type length where=(type=2)); proc contents data=&dsn2 noprint ...
639772df7971ec8cd90e2ae70576b1ee23cbd91c3213c95c957026f508ee478b
SAS
1,457
45
%macro StandardizeVarscanIDs(VarscanID_dsd,VarName,outdsd); data &outdsd; length _chr_ $5.; /*set &VarscanID_dsd(keep=&VarName);*/ set &VarscanID_dsd; &VarName=strip(left(&VarName)); _&VarName._=&VarName; if (prxmatch('/[()]/',&VarName)) then do; /*For Mut: chr22:19111641 ( G->T )*/ ...
68c54bcfde5f1e50c676f37d94340d14ab92af36ae3b0f153d19ecb91e5feb10
SAS
1,475
68
%macro check_header_DataRow( file, dlm='09'x, header_rown=1, data_rown=2, dsdout=header ); data &dsdout.1; length varname $200.; infile "&file" dsd dlm=&dlm firstobs=&header_rown obs=&header_rown; input varname @@; n=_n_; run; proc sql noprint; select max(n) into: tot_headers from &dsdout.1; quit; ...
b2e446d817e1ec78bf81a23c74521e7d26086ee4c046d4bcd699a603ea93f0ef
SAS
1,475
40
%macro combo(r)/parmbuff; %let i=2; %let things=; %do %while (%Qscan(&syspbuff,&i,%STR(,%))) ne ); %let p&i="%Qscan(&syspbuff,&i,%STR(,%)))"; %if &i=2 %then %let things=&&p&i; %else %let things=&things,&&p&i; %let i=%eval(&i+1); %end; %let n=%ev...
968131521ae08a4b81d587c280fecc16c80176062da0221f35ab7cb663c95c0d
SAS
1,486
81
%macro SQUEEZE_wide_dsd( dsdin, dsdout_prefix, split_num4vars, dsdout ); *Split large wide dsd; %split_wide_dsd( dsdin=&dsdin, dsdout_prefix=&dsdout_prefix, split_num4vars=&split_num4vars, dsdout4subdsd=subdsdinfo, delete_original_dsd=1 ); *Get the total number of vars in the subdsdinfo; data _null_; set subdsdinfo en...
c1f3b5216702cbd611019604dc79f8f9c91c5963280a95b87671d450d86baca5
SAS
1,509
62
%macro Header4VCF( vcf_file=, /*Create three global macro vars for using by other codes*/ global_header_num=vcf_header_num, global_colnames=vcf_colnames, global_vcfcolnums=vcfcolnums ); filename vcf "&vcf_file"; %global &global_header_num &global_colnames &global_vcfcolnums; *Reset values of these global mac...
6c6d154cd46385ab34a2ca41fd187335d3f2484ac2b782fddeeb1a6fe58d26c4
SAS
1,516
68
%macro geno2allelecolumns( dsd=, cols4genos=,/*such as 4-9 or %bquote(4-7,8); Use %bquote if containing comma among these column numbers!*/ outdsd=out ); %pull_column(dsd=&dsd,dsdout=&outdsd,cols2pull=&cols4genos); *get other columns not matching with these pulled columns; %pull_column(dsd=&dsd,dsdout=&outdsd._,...
942b8fe324e63abdb712287ba8e0e1564ad864c1d8eebb30a940f28d37f1c294
SAS
1,517
32
%macro permute(r) / parmbuff; /* the parmbuff option assigns */ %let i=2; /* the invocation parameter list to the */ %let things=; /* macro variable &syspbuff */ %do %while (%Qscan(&syspbuff,&i,%STR(,%))) ne ); /* scan the syspbuff */ %let p&i="...
cd0551f923a456345f27ad9c002b046a71088826390956132ef725fb5d114ec0
SAS
1,537
44
%macro get_genecode_gtf_data(gtf_gz_url,outdsd); %let OldOutDsd=&Outdsd; *If the outdsd contains lib abbreviation; *It is necessary to generate a gtf dsd in working directory first.; %if %index(&OldOutDsd,.) %then %do; %let outdsd=%scan(&outdsd,2,.); %end; %let wkdir=%sysfunc(getoption(work)); %let gtf_gz_file=%sysfu...
0d1eeeb55afb8c5da8ec95304ee476ad18ee8847b873b88dd0ea11eb040858d7
SAS
1,539
66
%macro infile_wide2long4sas( file,/*The first column contain char value, with other columns are numeric*/ dlm, dsdout ); filename dsd_hd "&file"; *The best way to infile wide format data into long format data for sas; data &dsdout; retain ncols 0; infile dsd_hd delimiter="&dlm" firstobs=1 obs=max truncover; ...
288dd5694b2592441cca065bcd2f84d4e9dd27a18e899a895717af17a52e00f3
SAS
1,550
80
%macro QureyMetaXcanTWAS4Genes( metaxcan_twas_file, ukb_twas_file, genes, dsdout, rawp_cutoff=0.01 ); proc import datafile="&metaxcan_twas_file" dbms=tab out=TWAS replace; getnames=yes;guessingrows=100000; run; proc import datafile="&ukb_twas_file" dbms=tab out=UKB replace; getnames=yes;guessingrows=100000...
aca79f024331b331d3b613e0b6e3326faec423347c64db74881573abd99c48f2
SAS
1,567
39
%macro permute(r) / parmbuff; /* the parmbuff option assigns */ %let i=2; /* the invocation parameter list to the */ %let things=; /* macro variable &syspbuff */ %do %while (%Qscan(&syspbuff,&i,%STR(,%))) ne ); /* scan the syspbuff */ %let p&i="...
b4cb80caea1faa5d8037e2d665dac250f00850c889118c539dcd2ca75a373c68
SAS
1,573
61
%macro AddMissingTag4Grps( dsdin=,/*Long format dsd with grp vars and numeric value var*/ grp_vars=, /*Group variables used to stratify numeric variable for missing test; Note: any numeric variable with missing value in a group will lead to the assigment of value 1 to the combination of these grp vars, meanwhile, ...
1ef0b0078916fe8c63e5d6448098acd24e3aa165d917b73e6911a3089a256789
SAS
1,582
53
%macro scASE_betabino( dsdin=x2, model_var=x , /*Currently it only accept one factor for the model statement*/ subj_var=subj, read_var=A_cnt, tot_var=tot outdsd=nlmParameterEstimates ); ods exclude all; *First estimate model parameters using proc fmm with betabinomial model; /*ods trace on;*/ ods output ...
2c06eb6ba92d9105674ac337d7cb7969861e2c142425aba9733f4aa6f335d9ac
SAS
1,585
52
%macro Bim2Annovar(bim_fullpath,dsdout,annovar_input,annovar_dir,annovar_outdir); data ANNOVAR(drop=A); length A1 A2 $32767.;*This is for avoiding truncation of large deletion; infile "&Plink_Bim..Bim" dlm='09'x dsd truncover lrecl=32767 length=linelen firstobs=1; input; Chr=input(scan(_infil...
e067d5e2cfaac487b3facddba3272a0ffb5cf42a5be0a8264e7aa642cebc89de
SAS
1,586
58
%macro idx4list_in_alphabet_ord( /*This macro is very useful for obtaining numeric index in an alphabetic sorted list for a query list; The output idx can be used in a macro loop or in a array at data step!*/ list= ,/*Blank space separated elements*/ outdsd=list_order, /*A sas dataset will be created to contain the...
483ce7e84a4fc70e4b6bcd800498288183d239d0e4ca75b581124a0be36aa78c
SAS
1,606
73
%macro QueryGTEx4GeneID( geneids=Apobec3a Apobec3b,/*For Apobec3a*/ genomeBuild=hg38,/*hg38, but hg19 is not supported by GTEx*/ outdsd=gene_info ); %let genomeBuild=%str(GRCh38/hg38); %if "&genomeBuild"="hg19" %then %do; %let genomeBuild=%str(GRCh37/hg19); %put The hg19 query does not work right now; %abor...
3fe50cbd907bf709eac86bc403e4d46c2a0be4cf86d6f581dbd0df3b1a195f50
SAS
1,617
71
%macro char_grp_to_num_grp4dups(dsdin,grp_vars4sort,descending_or_not,dsdout,num_grp_output_name); %let nvars=%numargs(&grp_vars4sort); data &dsdout; set &dsdin; %if &nvars>=1 %then %do; grps_output_key=catx(':', of &grp_vars4sort); %end; %else %do; grps_output_key=&grp_vars4sort; %end; run; /*All grp keys a...
0d16133428f0ffb98d049950a253fc5423e400b8f12b5d380edcabe5a182f445
SAS
1,652
62
%macro Prep_numgeno4fisher( dsin=, /* Input dataset name (already imported) */ snplist=, /* Space-separated list of SNP variable names */ outds=, /* Output dataset for fisher4cntdsd */ byvars=cancertype /* By variables, default as in your code */ ); /* Filter out missing p...
1bbbe0b647165dadd66b8583d5d20d6aaefe9fcdfa7fc2ad428b273b94e6152a
SAS
1,662
77
%macro OpenSVG_Printer( filename=mysvgfilename, svgfileref=out, other_paras4ods_graphics=%str( ), outdir=,/*output svg to the dir; if empty, it will save it into the dir %sysfunc(pathname(HOME));*/ ); *In Windows, due to sysfunc(pathname(HOME)) only works in Linux; *the SVG will be failed to be written into the SAS i...
26a864cb910889c8f93041c6a711951a626b5ecc6c143e112dd03a747212ee45
SAS
1,679
56
/* Here is another version of David's macro. It eliminates the need to place surrounding symbols around the list. Some may see this as advantage, while others may think it a disadvantage. It also allows the separator to be any of the standard ones accepted by SCAN and used in a legal manner ( i.e. no use of 1(2...