└── README.md /README.md: -------------------------------------------------------------------------------- 1 | SAS to Python guide 2 | =================== 3 | 4 | `proc freq` 5 | ----------- 6 | 7 | ```SAS 8 | proc freq data=mydata; 9 | tables myvar / nocol nopercent nocum; 10 | run; 11 | ``` 12 | 13 | ```python 14 | mydata.myvar.value_counts().sort_index() 15 | ``` 16 | 17 | 18 | #### sort by frequency #### 19 | 20 | ```SAS 21 | proc freq order=freq data=mydata; 22 | tables myvar / nocol nopercent nocum; 23 | run; 24 | ``` 25 | 26 | ```python 27 | mydata.myvar.value_counts() 28 | ``` 29 | 30 | 31 | #### with missing #### 32 | 33 | ```SAS 34 | proc freq order=freq data=mydata; 35 | tables myvar / nocol nopercent nocum missing; 36 | run; 37 | ``` 38 | 39 | ```python 40 | mydata.myvar.value_counts(dropna=False) 41 | ``` 42 | 43 | 44 | `proc means` 45 | ------------ 46 | 47 | ```SAS 48 | proc means data=mydata n mean std min max p25 median p75; 49 | var myvar; 50 | run; 51 | ``` 52 | 53 | ```python 54 | mydata.myvar.describe() 55 | ``` 56 | 57 | 58 | #### more percentiles #### 59 | 60 | ```SAS 61 | proc means data=mydata n mean std min max p1 p5 p10 p25 median p75 p90 p95 p99; 62 | var myvar; 63 | run; 64 | ``` 65 | 66 | ```python 67 | mydata.myvar.describe(percentiles=[.01, .05, .1, .25, .5, .75, .9, .95, .99]) 68 | ``` 69 | 70 | 71 | `data` step 72 | ----------- 73 | 74 | #### concatenate datasets #### 75 | 76 | ```SAS 77 | data concatenated; 78 | set mydata1 mydata2; 79 | run; 80 | ``` 81 | 82 | ```python 83 | concatenated = pandas.concat([mydata1, mydata2]) 84 | ``` 85 | 86 | 87 | `proc contents` 88 | --------------- 89 | 90 | ```SAS 91 | proc contents data=mydata; 92 | run; 93 | ``` 94 | 95 | ```python 96 | mydata.info() 97 | ``` 98 | 99 | #### save output #### 100 | 101 | ```SAS 102 | proc contents noprint data=mydata out=contents; 103 | run; 104 | ``` 105 | 106 | ```python 107 | contents = mydata.info() # check this is right 108 | ``` 109 | 110 | 111 | Misc 112 | ---- 113 | 114 | #### number of rows in a datastep #### 115 | 116 | ```SAS 117 | * haha nice try. Try this for size: http://www2.sas.com/proceedings/sugi26/p095-26.pdf; 118 | ``` 119 | 120 | ```python 121 | len(mydata) 122 | ``` 123 | --------------------------------------------------------------------------------