-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzipincome.sas
348 lines (271 loc) · 6.17 KB
/
zipincome.sas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
PROC IMPORT OUT= WORK.Zip_income
DATAFILE= "C:\Users\sanja\Desktop\GMAT\STEVENS MSBA\1stSem\S
AS_KashaDehnad\SAS_data\zipcodeagi13.csv"
DBMS=CSV REPLACE;
GETNAMES=YES;
DATAROW=2;
RUN;
*IRS Dataset work;
/*Nogoood zip=0000 or 9999
NJzip zip=NJ
NYzip zip=NY
Rest zip=all other
STATE ZIPCODE AGI_STUB N1 A02650*/
data Nogood NJzip NYzip rest;
set Zip_income(keep=STATEFIPS STATE ZIPCODE AGI_STUB N1 A02650);
if zipcode='00000' or zipcode='99999' then output Nogood;
else if state='NJ' then output NJzip;
else if state='NY' then output NYzip;
else output Rest;
run;
Libname sasdata "C:\Users\sanja\Desktop\GMAT\STEVENS MSBA\1stSem\SAS_KashaDehnad\SAS_data" access=read;
Libname sasdata "C:\Users\sanja\Google Drive (spattana@stevens.edu)\Desktop\GMAT\STEVENS MSBA\1stSem\SAS_KashaDehnad\SAS_data" access=read;
proc datasets libname=sasdata;
run;
proc contents data=sasdata.STRESS_TEST;
run;
proc copy in=sasdata out=work;
select STRESS_TEST STRESS_PATIENTS;
run;
/*Merge/Combine files to give one file*/
proc sort data=STRESS_PATIENTS out=STRESS_PATIENTS2;
by Patient_ID;
run;
proc sort data=STRESS_TEST out=STRESS_TEST2;
by Patient_ID;
run;
data both;
merge STRESS_PATIENTS
STRESS_TEST
;
run;
data both;
merge STRESS_PATIENTS
STRESS_TEST
;
by Patient_ID;
run;
proc sql;
create table both_sql as
select a.*
,b.*
from STRESS_PATIENTS a
,STRESS_TEST b
where a.Patient_ID = b.Patient_ID
;
quit;
proc sort data=STRESS_PATIENTS out=STRESS_PATIENTS2 nodupkey;
by Patient_ID;
run;
proc sort data=STRESS_TEST out=STRESS_TEST2 nodupkey;
by Patient_ID;
run;
data both;
merge STRESS_PATIENTS2
STRESS_TEST2
;
by Patient_ID;
run;
proc sql;
create table both_sql as
select a.*
,b.*
from STRESS_PATIENTS2 a
,STRESS_TEST2 b
where a.Patient_ID = b.Patient_ID
;
quit;
data both;
merge STRESS_PATIENTS2(in=infirst)
STRESS_TEST2(in=insecond)
;
by Patient_ID;
if infirst and insecond then output;
run;
data both notest;
merge STRESS_PATIENTS2(in=infirst)
STRESS_TEST2(in=insecond)
;
by Patient_ID;
if infirst and insecond then output both;
else if infirst and not insecond then output notest;
run;
data both notest;
merge STRESS_PATIENTS2(in=infirst)
STRESS_TEST2(in=insecond)
;
by Patient_ID;
dsn1=infirst; *program data vector PDV;
dsn2=insecond;
if infirst and insecond then output both;
else if infirst and not insecond then output notest;
run;
data both notest;
drop TimeMin TimeSec;
retain cum_sec;
merge STRESS_PATIENTS2(in=infirst)
STRESS_TEST2(in=insecond)
;
by Patient_ID;
total_sec=TimeMin*60+TimeSec;
cum_sec=cum_sec+total_sec;
if infirst and insecond then output both;
else if infirst and not insecond then output notest;
run;
data both;
set both;
drop cum_sec;
drop drop;
run;
data both2;
retain cum_sec;
set both;
if _n_=1 then cum_sec=0;
*by Patient_ID;
cum_sec=cum_sec+total_sec;
run;
data both2;
retain cum_sec 0;
set both;
*if _n_=1 then cum_sec=0;
*by Patient_ID;
cum_sec=cum_sec+total_sec;
run;
*Output if not used then the current table/dataset is overwritten;
proc sort data=both;
by Tolerance;
run;
data both2;
*retain cum_sec 0;
set both;
by Tolerance;
var1=first.Tolerance;
var2=last.Tolerance;
*if first.Tolerance then cum_sec=0;
else
output;
run;
data both2;
retain cum_sec;
set both;
by Tolerance;
if first.Tolerance then cum_sec=0;
cum_sec=cum_sec+total_sec;
output;
run;
data work.earn(drop=i);
investment=1000;
payment=10;
do i=1 to 30;
interest=investment*.05;
year+1;
investment+interest;
output;
end;
run;
data junk;
do;
x=1;
y=20;
z='this is a test';
output;
end;
run;
proc sort data=Njzip;
by zipcode;
run;
data Njzip2;
set Njzip;
by zipcode;
var1=first.zipcode;
var2=last.zipcode;
output;
run;
data Njzip3;
retain total_count;
retain total_money;
set Njzip;
by zipcode;
if first.zipcode then total_count=0;
total_count=total_count+N1;
if first.zipcode then total_money=0;
total_money=total_money+A02650;
if last.zipcode then do average=total_money/total_count;
output;
end;
run;
data Njzip2;
retain total_money;
set Njzip;
by zipcode;
if first.zipcode then total_money=0;
total_money=total_money+A02650;
output;
run;
*Average;
data Njzip3;
*retain average;
set Njzip2;
by zipcode;
if last.zipcode then average=0;
average=total_money/total_count;
output;
run;
proc sort data=NJzip; by zipcode agi_stub; run;
data njzip;
keep state zipcode N1 A02650;
set income_by_zip;
if zipcode=0 or zipcode=99999 then delete;
if state='NJ' then output njzip;
run;
proc sort data=NJzip; by zipcode agi_stub; run;
data nj_smmary;
retain total_count total_money;
keep zipcode total_count total_money average;
set NJzip;
by zipcode;
if zipcode=0 or zipcode=99999 then delete;
if first.zipcode then do;
total_count=0;
total_money=0;
end;
total_count=total_count+n1;
total_money=total_money+A02650;
if last.zipcode then do;
average=total_money/total_count;
output;
end;
run;
%let st=NY;
%macro mzipmoney(st=NJ);
data &st.zip;
keep state zipcode agi_stub N1 A02650;
set Zip_income;
if zipcode=0 or zipcode=99999 then delete;
if state="&st." then output &st.zip;
run;
* single quote exact match, double quote variable example & usge ;
proc sort data=&st.zip; by zipcode agi_stub; run;
data &st._smmary;
retain total_count total_money;
keep zipcode total_count total_money average;
set &st.zip;
by zipcode;
if zipcode=0 or zipcode=99999 then delete;
if first.zipcode then do;
total_count=0;
total_money=0;
end;
total_count=total_count+n1;
total_money=total_money+A02650;
if last.zipcode then do;
average=total_money/total_count;
output;
end;
title "This is processing for state of &st. "; *nothing next to &st then dot not mandatory;
proc print data=&st.summary;
var zipcode total_count total_money average;
run;
%mend;
%mzipmoney(st=AL);
%mzipmoney *calculates for NJ;