-
Notifications
You must be signed in to change notification settings - Fork 0
/
QSDB Step2 Crops COUNTY revenue 20220312.sas
860 lines (779 loc) · 28.9 KB
/
QSDB Step2 Crops COUNTY revenue 20220312.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
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
/* Start timer */
%let _timer_start = %sysfunc(datetime());
DM "CLEAR LOG ; CLEAR OUTPUT ; ";
options source2 ls=80 ps=60 cpucount=8 fullstimer formchar="|----|+|---+=|-/\<>*";
/*************************************************************/
/************** NASS complete database **** Saleem, Shaik ***/
Title 'NASS QSBD Saleem SHAIK - March, Oct 2021';
/*************************************************************/
/*
Saleem Shaik, Ph.D
Branch Chief
Agricultural Policy and Models Branch
ERS, USDA
*/
/*************************************************************/
/*************************************************************/
LIBNAME NASS2 'C:\Users\Saleem.Shaik\OneDrive - USDA\Saleem.Shaik\papers\dataforanalysis\NASS';
LIBNAME NASS3 'C:\Users\Saleem.Shaik\OneDrive - USDA\Saleem.Shaik\papers\dataforanalysis\SCP\domestic';
LIBNAME CLIM "C:\Users\Saleem.Shaik\OneDrive - USDA\Saleem.Shaik\papers\dataforanalysis\Climate";
LIBNAME CLIM1 "C:\Users\Saleem.Shaik\OneDrive - USDA\Saleem.Shaik\papers\analysis\climate";
/*************************************************************/
/*************************************************************/
/*
LIBNAME NASS1 "\\usda.net\ers\MTEDCOMMON\APM\STAFF\SShaik\US\data";
LIBNAME NASS2 "\\usda.net\ers\MTEDCOMMON\APM\STAFF\SShaik\US\dataforanalysis\NASS";
LIBNAME NASS3 "\\usda.net\ers\MTEDCOMMON\APM\STAFF\SShaik\US\dataforanalysis\SCP";
LIBNAME NASS1 'C:\Users\Saleem.Shaik\OneDrive - USDA\Saleem.Shaik\papers\dataforanalysis\NASS';
LIBNAME NASS2 'C:\Users\Saleem.Shaik\OneDrive - USDA\Saleem.Shaik\papers\dataforanalysis\SCP';
LIBNAME CLIM "C:\Users\Saleem.Shaik\OneDrive - USDA\Saleem.Shaik\papers\dataforanalysis\Climate";
LIBNAME CLIM1 "C:\Users\Saleem.Shaik\OneDrive - USDA\Saleem.Shaik\papers\analysis\climate";
*/
/*************************************************************/
%let yrmonday = 20220312.;
%let yrmonday1 = 20220312;
/*************************************************************/
/*************************************************************/
/*************************************************************/
data PRICE REVENUE PRODUCTION COUNTY_PRODUCTION check;
set NASS2.step1_QS_Crops;
if STATISTICCAT_DESC IN ('PRODUCTION') AND
UNIT_DESC IN ('$', '$ / TON', '$, CHERRY BASIS',
'$, ON TREE EQUIV', '$, PHD EQUIV')
then STATISTICCAT_DESC = 'PRODUCTION in $';
if AGG_LEVEL_DESC IN ('STATE', 'NATIONAL') AND
STATISTICCAT_DESC IN ('PRICE RECEIVED') AND
UTIL_PRACTICE_DESC IN ('ALL UTILIZATION PRACTICES',
'GRAIN', 'SUGAR') then output PRICE;
if AGG_LEVEL_DESC IN ('STATE', 'NATIONAL') AND
STATISTICCAT_DESC IN ('PRODUCTION in $') AND
UTIL_PRACTICE_DESC IN ('ALL UTILIZATION PRACTICES',
'GRAIN', 'SUGAR') AND
FREQ_DESC IN ('ANNUAL') then output REVENUE;
if AGG_LEVEL_DESC IN ('STATE', 'NATIONAL') AND
STATISTICCAT_DESC IN ('PRODUCTION') AND
UTIL_PRACTICE_DESC IN ('ALL UTILIZATION PRACTICES',
'GRAIN', 'SUGAR') AND
FREQ_DESC IN ('ANNUAL') then output PRODUCTION;
if AGG_LEVEL_DESC IN ('COUNTY') AND
STATISTICCAT_DESC IN ('PRODUCTION') AND
UTIL_PRACTICE_DESC IN ('ALL UTILIZATION PRACTICES',
'GRAIN', 'SUGAR') then output COUNTY_PRODUCTION;
if AGG_LEVEL_DESC IN ('NATIONAL') AND
COMMODITY_DESC IN ('CANOLA') then output check;
run;
/*************************************************************/
/*************************************************************/
/*************************************************************/
* Create STATE PRICE dataset;
/*************************************************************/
data PRICES_ST_1(keep=AGG_LEVEL_DESC
COMMODITY_GROUP_code COMMODITY_GROUP
SOURCE_DESC SECTOR_DESC GROUP_DESC COMMODITY_DESC
CLASS_DESC PRODN_PRACTICE_DESC UTIL_PRACTICE_DESC
STATISTICCAT_DESC UNIT_DESC
STATE_FIPS_CODE STATE_NAME
YEAR REFERENCE_PERIOD_DESC FREQ_DESC VALUE VALUE1);
set PRICE;
WHERE AGG_LEVEL_DESC IN ('STATE', 'NATIONAL') AND
STATISTICCAT_DESC IN ('PRICE RECEIVED') AND
/*FREQ_DESC IN ('ANNUAL', 'MONTHLY') AND
*/REFERENCE_PERIOD_DESC IN ('MARKETING YEAR', 'YEAR',
'JAN', 'FEB', 'MAR', 'APR', 'MAY', 'JUN',
'JUL', 'AUG', 'SEP', 'OCT', 'NOV', 'DEC') AND
UNIT_DESC NOTIN ('PCT', 'PCT BY COLOR', 'PCT BY GRADE',
'PCT BY TYPE', 'PCT OF PARITY',
'PCT OF PRODUCTION', 'PCT OF TOTAL STOCKS');
* PRICES = value1;
* PRICES_unit=UNIT_DESC;
run;
data PRICES_ST_Annual PRICES_ST_month;
set PRICES_ST_1;
if REFERENCE_PERIOD_DESC = 'MARKETING YEAR' then
REFERENCE_PERIOD_DESC = 'MARKETING YEAR PRICES';
if REFERENCE_PERIOD_DESC = 'YEAR' then
REFERENCE_PERIOD_DESC = 'CALENDER YEAR PRICES';
if REFERENCE_PERIOD_DESC IN ('MARKETING YEAR PRICES',
'CALENDER YEAR PRICES') then output PRICES_ST_Annual;
else if REFERENCE_PERIOD_DESC IN ('JAN', 'FEB', 'MAR',
'APR', 'MAY', 'JUN', 'JUL', 'AUG', 'SEP',
'OCT', 'NOV', 'DEC') then output PRICES_ST_month;
run;
proc sort data=PRICES_ST_Annual
DUPout=DUP_PRICES_ST_1_annual NODUPKEY
OUT=PRICES_ST_Annual_1;
where FREQ_DESC in ('ANNUAL');
by AGG_LEVEL_DESC
COMMODITY_GROUP_code COMMODITY_GROUP
SOURCE_DESC SECTOR_DESC GROUP_DESC COMMODITY_DESC
CLASS_DESC PRODN_PRACTICE_DESC UTIL_PRACTICE_DESC
STATISTICCAT_DESC UNIT_DESC
STATE_FIPS_CODE STATE_NAME
YEAR
REFERENCE_PERIOD_DESC;
run;
proc transpose data=PRICES_ST_Annual_1 out=PRICES_ST_Annual_2(drop=_NAME_);
where FREQ_DESC in ('ANNUAL');
id REFERENCE_PERIOD_DESC;
idlabel REFERENCE_PERIOD_DESC;
var VALUE1;
by AGG_LEVEL_DESC
COMMODITY_GROUP_code COMMODITY_GROUP
SOURCE_DESC SECTOR_DESC GROUP_DESC COMMODITY_DESC
CLASS_DESC PRODN_PRACTICE_DESC UTIL_PRACTICE_DESC
STATISTICCAT_DESC UNIT_DESC
STATE_FIPS_CODE STATE_NAME
YEAR;
run;
proc sort data=PRICES_ST_Month
DUPout=DUP_PRICES_ST_Month_1 NODUPKEY
OUT=PRICES_ST_Month_1;
where FREQ_DESC notin ('ANNUAL');
by AGG_LEVEL_DESC
COMMODITY_GROUP_code COMMODITY_GROUP
SOURCE_DESC SECTOR_DESC GROUP_DESC COMMODITY_DESC
CLASS_DESC PRODN_PRACTICE_DESC UTIL_PRACTICE_DESC
STATISTICCAT_DESC UNIT_DESC
STATE_FIPS_CODE STATE_NAME
YEAR
REFERENCE_PERIOD_DESC;
run;
proc transpose data=PRICES_ST_Month_1 out=PRICES_ST_Month_2(drop=_NAME_) prefix=Price_;
where FREQ_DESC NOTIN ('ANNUAL');
id REFERENCE_PERIOD_DESC;
idlabel REFERENCE_PERIOD_DESC;
var VALUE1;
by AGG_LEVEL_DESC
COMMODITY_GROUP_code COMMODITY_GROUP
SOURCE_DESC SECTOR_DESC GROUP_DESC COMMODITY_DESC
CLASS_DESC PRODN_PRACTICE_DESC UTIL_PRACTICE_DESC
STATISTICCAT_DESC UNIT_DESC
STATE_FIPS_CODE STATE_NAME
YEAR;
run;
data PRICES_ST_3;
retain Merge_ST_price;
merge PRICES_ST_Annual_2(in=b) PRICES_ST_Month_2(in=a);
by AGG_LEVEL_DESC
COMMODITY_GROUP_code COMMODITY_GROUP
SOURCE_DESC SECTOR_DESC GROUP_DESC COMMODITY_DESC
CLASS_DESC PRODN_PRACTICE_DESC UTIL_PRACTICE_DESC
STATISTICCAT_DESC UNIT_DESC
STATE_FIPS_CODE STATE_NAME
YEAR;
if a and b then Merge_ST_price='Annual and Monthly'; else
if a then Merge_ST_price='Annual'; else
if b then Merge_ST_price='Monthly';
run;
proc freq data=PRICES_ST_3; table Merge_ST_price; run;
data PRICES_ST_4;
set PRICES_ST_3;
JD_PRICES_N= N(of Price_JAN, Price_FEB, Price_MAR,
Price_APR, Price_MAY, Price_JUN,
Price_JUL, Price_AUG, Price_SEP,
Price_OCT, Price_NOV, Price_DEC);
if JD_PRICES_N>3 then
JD_PRICES= mean(of Price_JAN, Price_FEB, Price_MAR,
Price_APR, Price_MAY, Price_JUN,
Price_JUL, Price_AUG, Price_SEP,
Price_OCT, Price_NOV, Price_DEC);
proc sort;
by AGG_LEVEL_DESC COMMODITY_GROUP_code COMMODITY_GROUP
SOURCE_DESC SECTOR_DESC GROUP_DESC COMMODITY_DESC
CLASS_DESC PRODN_PRACTICE_DESC UTIL_PRACTICE_DESC
STATISTICCAT_DESC UNIT_DESC
STATE_FIPS_CODE STATE_NAME YEAR;
run;
data PRICES_ST_5(Keep=Merge_ST_price
AGG_LEVEL_DESC
COMMODITY_GROUP_code COMMODITY_GROUP
SOURCE_DESC SECTOR_DESC GROUP_DESC COMMODITY_DESC
CLASS_DESC PRODN_PRACTICE_DESC UTIL_PRACTICE_DESC
STATISTICCAT_DESC PRICES_unit
STATE_FIPS_CODE STATE_NAME YEAR
MARKETING_YEAR_PRICES MARKETING_YEAR_PRICES1
MARKETING_YEAR_PRICES2 CALENDER_YEAR_PRICES
JD_PRICES JD_PRICES_N
Price_JAN Price_FEB Price_MAR
Price_APR Price_MAY Price_JUN
Price_JUL Price_AUG Price_SEP
Price_OCT Price_NOV Price_DEC);
retain Merge_ST_price
AGG_LEVEL_DESC
COMMODITY_GROUP_code COMMODITY_GROUP
SOURCE_DESC SECTOR_DESC GROUP_DESC COMMODITY_DESC
CLASS_DESC PRODN_PRACTICE_DESC UTIL_PRACTICE_DESC
STATISTICCAT_DESC PRICES_unit
STATE_FIPS_CODE STATE_NAME YEAR
MARKETING_YEAR_PRICES MARKETING_YEAR_PRICES1
MARKETING_YEAR_PRICES2 CALENDER_YEAR_PRICES
JD_PRICES JD_PRICES_N
Price_JAN Price_FEB Price_MAR
Price_APR Price_MAY Price_JUN
Price_JUL Price_AUG Price_SEP
Price_OCT Price_NOV Price_DEC;
set PRICES_ST_4;
if MARKETING_YEAR_PRICES = . then
MARKETING_YEAR_PRICES1=CALENDER_YEAR_PRICES; else
MARKETING_YEAR_PRICES1=MARKETING_YEAR_PRICES;
if MARKETING_YEAR_PRICES1 = . then
MARKETING_YEAR_PRICES2=JD_PRICES; else
MARKETING_YEAR_PRICES2=MARKETING_YEAR_PRICES1;
PRICES_unit=UNIT_DESC;
proc sort;
by AGG_LEVEL_DESC
COMMODITY_GROUP_code COMMODITY_GROUP
SOURCE_DESC SECTOR_DESC GROUP_DESC COMMODITY_DESC
CLASS_DESC PRODN_PRACTICE_DESC UTIL_PRACTICE_DESC
STATISTICCAT_DESC PRICES_unit
STATE_FIPS_CODE STATE_NAME YEAR;
run;
data PRICES_ST_6(Keep=Merge_ST_price
AGG_LEVEL_DESC
COMMODITY_GROUP_code COMMODITY_GROUP
SOURCE_DESC SECTOR_DESC GROUP_DESC COMMODITY_DESC
CLASS_DESC PRODN_PRACTICE_DESC UTIL_PRACTICE_DESC
STATISTICCAT_DESC PRICES_unit
STATE_FIPS_CODE STATE_NAME YEAR
MARKETING_YEAR_PRICES MARKETING_YEAR_PRICES1
MARKETING_YEAR_PRICES2);
set PRICES_ST_5;
proc sort;
by AGG_LEVEL_DESC
COMMODITY_GROUP_code COMMODITY_GROUP
SOURCE_DESC SECTOR_DESC GROUP_DESC COMMODITY_DESC
CLASS_DESC PRODN_PRACTICE_DESC UTIL_PRACTICE_DESC
STATISTICCAT_DESC PRICES_unit
STATE_FIPS_CODE STATE_NAME YEAR;
run;
data PRICES_ST_7(Keep=Merge_ST_price
AGG_LEVEL_DESC
COMMODITY_GROUP_code COMMODITY_GROUP
SOURCE_DESC SECTOR_DESC GROUP_DESC COMMODITY_DESC
CLASS_DESC PRODN_PRACTICE_DESC UTIL_PRACTICE_DESC
STATISTICCAT_DESC PRICES_unit
STATE_FIPS_CODE STATE_NAME YEAR
MARKETING_YEAR_PRICES MARKETING_YEAR_PRICES1
MARKETING_YEAR_PRICES2);
set PRICES_ST_6;
proc sort;
by AGG_LEVEL_DESC
COMMODITY_GROUP_code COMMODITY_GROUP
SOURCE_DESC SECTOR_DESC GROUP_DESC COMMODITY_DESC
CLASS_DESC PRODN_PRACTICE_DESC UTIL_PRACTICE_DESC
STATISTICCAT_DESC PRICES_unit
STATE_FIPS_CODE STATE_NAME YEAR;
run;
data PRICES_ST_8(Keep=Merge_ST_price
COMMODITY_GROUP_code COMMODITY_GROUP
SOURCE_DESC SECTOR_DESC GROUP_DESC COMMODITY_DESC
CLASS_DESC UTIL_PRACTICE_DESC
PRICES_unit_st
STATE_FIPS_CODE STATE_NAME YEAR
MARKETING_YEAR_PRICES MARKETING_YEAR_PRICES1
MARKETING_YEAR_PRICES2);
set PRICES_ST_7;
PRICES_unit_st=PRICES_unit;
proc sort;
by COMMODITY_GROUP_code COMMODITY_GROUP
SOURCE_DESC SECTOR_DESC GROUP_DESC COMMODITY_DESC
CLASS_DESC UTIL_PRACTICE_DESC
STATE_FIPS_CODE STATE_NAME YEAR;
run;
/*************************************************************/
/*************************************************************/
/*************************************************************/
/*************************************************************/
/*************************************************************/
* Create STATE REVENUE dataset;
/*************************************************************/
data REVENUE_ST_1(keep=AGG_LEVEL_DESC
COMMODITY_GROUP_code COMMODITY_GROUP
SOURCE_DESC SECTOR_DESC GROUP_DESC COMMODITY_DESC
CLASS_DESC UTIL_PRACTICE_DESC
STATISTICCAT_DESC UNIT_DESC
STATE_FIPS_CODE STATE_NAME
YEAR REFERENCE_PERIOD_DESC FREQ_DESC VALUE VALUE1);
set REVENUE;
WHERE REFERENCE_PERIOD_DESC IN ('YEAR');
run;
data REVENUE_ST_2(Keep=AGG_LEVEL_DESC
COMMODITY_GROUP_code COMMODITY_GROUP
SOURCE_DESC SECTOR_DESC GROUP_DESC COMMODITY_DESC
CLASS_DESC UTIL_PRACTICE_DESC
REVENUE_unit
STATE_FIPS_CODE STATE_NAME YEAR
REVENUE);
set REVENUE_ST_1;
REVENUE = value1;
REVENUE_unit =UNIT_DESC;
proc sort;
by AGG_LEVEL_DESC COMMODITY_GROUP_code COMMODITY_GROUP
SOURCE_DESC SECTOR_DESC GROUP_DESC COMMODITY_DESC
CLASS_DESC UTIL_PRACTICE_DESC
STATE_FIPS_CODE STATE_NAME YEAR;
run;
data PRODUCTION_ST_1(keep=AGG_LEVEL_DESC
COMMODITY_GROUP_code COMMODITY_GROUP
SOURCE_DESC SECTOR_DESC GROUP_DESC COMMODITY_DESC
CLASS_DESC PRODN_PRACTICE_DESC UTIL_PRACTICE_DESC
STATISTICCAT_DESC UNIT_DESC
STATE_FIPS_CODE STATE_NAME
YEAR REFERENCE_PERIOD_DESC FREQ_DESC VALUE VALUE1);
set PRODUCTION;
WHERE REFERENCE_PERIOD_DESC IN ('YEAR');
run;
data PRODUCTION_ST_2(Keep=AGG_LEVEL_DESC
COMMODITY_GROUP_code COMMODITY_GROUP
SOURCE_DESC SECTOR_DESC GROUP_DESC COMMODITY_DESC
CLASS_DESC PRODN_PRACTICE_DESC UTIL_PRACTICE_DESC
PRODUCTION_unit
STATE_FIPS_CODE STATE_NAME YEAR
PRODUCTION);
set PRODUCTION_ST_1;
PRODUCTION = value1;
PRODUCTION_unit =UNIT_DESC;
proc sort;
by AGG_LEVEL_DESC COMMODITY_GROUP_code COMMODITY_GROUP
SOURCE_DESC SECTOR_DESC GROUP_DESC COMMODITY_DESC
CLASS_DESC UTIL_PRACTICE_DESC
STATE_FIPS_CODE STATE_NAME YEAR;
run;
/*************************************************************/
/*************************************************************/
data PRODUCTION_REVENUE;
retain Merge_ST_PRODREV;
merge PRODUCTION_ST_2(in=a) REVENUE_ST_2(in=b);
by AGG_LEVEL_DESC COMMODITY_GROUP_code COMMODITY_GROUP
SOURCE_DESC SECTOR_DESC GROUP_DESC COMMODITY_DESC
CLASS_DESC UTIL_PRACTICE_DESC
STATE_FIPS_CODE STATE_NAME YEAR;
if a and b then Merge_ST_PRODREV='PRODUCTION & REVENUE'; else
if a then Merge_ST_PRODREV='PRODUCTION'; else
if b then Merge_ST_PRODREV='REVENUE';
run;
proc freq data=PRODUCTION_REVENUE;
table COMMODITY_DESC*Merge_ST_PRODREV/norow nocol nocum nopercent;
run;
data PRODUCTION_REVENUE_1;
set PRODUCTION_REVENUE;
if PRODUCTION>0 and REVENUE>0 then
PRICES=REVENUE/PRODUCTION;
run;
data PRODUCTION_REVENUE_2(keep=AGG_LEVEL_DESC
COMMODITY_GROUP_code COMMODITY_GROUP
SOURCE_DESC SECTOR_DESC GROUP_DESC COMMODITY_DESC
CLASS_DESC PRODN_PRACTICE_DESC UTIL_PRACTICE_DESC
STATE_FIPS_CODE STATE_NAME YEAR
PRODUCTION PRODUCTION_unit
REVENUE REVENUE_unit
PRICES);
set PRODUCTION_REVENUE_1;
run;
proc sort data=PRODUCTION_REVENUE_2
DUPout=DUP_PRODUCTION_REVENUE_2 NODUPKEY
OUT=PRODUCTION_REVENUE_3;
by COMMODITY_GROUP_code COMMODITY_GROUP
SOURCE_DESC SECTOR_DESC GROUP_DESC COMMODITY_DESC
CLASS_DESC PRODN_PRACTICE_DESC UTIL_PRACTICE_DESC
STATE_FIPS_CODE STATE_NAME YEAR AGG_LEVEL_DESC
PRODUCTION REVENUE ;
run;
/*************************************************************/
/*************************************************************/
/*************************************************************/
* Flag 5D - Create STATE PRICES dataset;
/*************************************************************/
/*************************************************************/
/*************************************************************/
data PRICES_US_1(keep=AGG_LEVEL_DESC
COMMODITY_GROUP_code COMMODITY_GROUP
SOURCE_DESC SECTOR_DESC GROUP_DESC COMMODITY_DESC
CLASS_DESC PRODN_PRACTICE_DESC UTIL_PRACTICE_DESC
STATISTICCAT_DESC UNIT_DESC
STATE_FIPS_CODE STATE_NAME
YEAR REFERENCE_PERIOD_DESC FREQ_DESC VALUE VALUE1);
set PRICE;
WHERE AGG_LEVEL_DESC IN ('NATIONAL') AND
STATISTICCAT_DESC IN ('PRICE RECEIVED') AND
/*FREQ_DESC IN ('ANNUAL', 'MONTHLY') AND
*/REFERENCE_PERIOD_DESC IN ('MARKETING YEAR', 'YEAR',
'JAN', 'FEB', 'MAR', 'APR', 'MAY', 'JUN',
'JUL', 'AUG', 'SEP', 'OCT', 'NOV', 'DEC') AND
UNIT_DESC NOTIN ('PCT', 'PCT BY COLOR', 'PCT BY GRADE',
'PCT BY TYPE', 'PCT OF PARITY',
'PCT OF PRODUCTION', 'PCT OF TOTAL STOCKS');
* PRICES = value1;
* PRICES_unit=UNIT_DESC;
run;
/*
proc means data=PRICES_US_1_US mean noprint;
class COMMODITY_DESC CLASS_DESC PRODN_PRACTICE_DESC UTIL_PRACTICE_DESC FREQ_DESC REFERENCE_PERIOD_DESC YEAR;
types () COMMODITY_DESC*CLASS_DESC*PRODN_PRACTICE_DESC*UTIL_PRACTICE_DESC*FREQ_DESC*REFERENCE_PERIOD_DESC*YEAR;
var VALUE1;
output out=sumstat_US;
run;
data sumstat_US_a; set sumstat_US; where _STAT_='MEAN';run;
*/
data PRICES_US_Annual PRICES_US_month;
set PRICES_US_1;
if REFERENCE_PERIOD_DESC = 'MARKETING YEAR' then
REFERENCE_PERIOD_DESC = 'MARKETING YEAR PRICES';
if REFERENCE_PERIOD_DESC = 'YEAR' then
REFERENCE_PERIOD_DESC = 'CALENDER YEAR PRICES';
if REFERENCE_PERIOD_DESC IN ('MARKETING YEAR PRICES',
'CALENDER YEAR PRICES') then output PRICES_US_Annual;
else if REFERENCE_PERIOD_DESC IN ('JAN', 'FEB', 'MAR',
'APR', 'MAY', 'JUN', 'JUL', 'AUG', 'SEP',
'OCT', 'NOV', 'DEC') then output PRICES_US_month;
run;
proc sort data=PRICES_US_Annual
DUPout=DUP_PRICES_US_1_annual NODUPKEY
OUT=PRICES_US_Annual_1;
where FREQ_DESC in ('ANNUAL');
by AGG_LEVEL_DESC
COMMODITY_GROUP_code COMMODITY_GROUP
SOURCE_DESC SECTOR_DESC GROUP_DESC COMMODITY_DESC
CLASS_DESC PRODN_PRACTICE_DESC UTIL_PRACTICE_DESC
STATISTICCAT_DESC UNIT_DESC
STATE_FIPS_CODE STATE_NAME
YEAR
REFERENCE_PERIOD_DESC;
run;
proc transpose data=PRICES_US_Annual_1 out=PRICES_US_Annual_2(drop=_NAME_);
where FREQ_DESC in ('ANNUAL');
id REFERENCE_PERIOD_DESC;
idlabel REFERENCE_PERIOD_DESC;
var VALUE1;
by AGG_LEVEL_DESC
COMMODITY_GROUP_code COMMODITY_GROUP
SOURCE_DESC SECTOR_DESC GROUP_DESC COMMODITY_DESC
CLASS_DESC PRODN_PRACTICE_DESC UTIL_PRACTICE_DESC
STATISTICCAT_DESC UNIT_DESC
STATE_FIPS_CODE STATE_NAME
YEAR;
run;
proc sort data=PRICES_US_Month
DUPout=DUP_PRICES_US_Month_1 NODUPKEY
OUT=PRICES_US_Month_1;
where FREQ_DESC notin ('ANNUAL');
by AGG_LEVEL_DESC
COMMODITY_GROUP_code COMMODITY_GROUP
SOURCE_DESC SECTOR_DESC GROUP_DESC COMMODITY_DESC
CLASS_DESC PRODN_PRACTICE_DESC UTIL_PRACTICE_DESC
STATISTICCAT_DESC UNIT_DESC
STATE_FIPS_CODE STATE_NAME
YEAR
REFERENCE_PERIOD_DESC;
run;
proc transpose data=PRICES_US_Month_1 out=PRICES_US_Month_2(drop=_NAME_) prefix=Price_;
where FREQ_DESC NOTIN ('ANNUAL');
id REFERENCE_PERIOD_DESC;
idlabel REFERENCE_PERIOD_DESC;
var VALUE1;
by AGG_LEVEL_DESC
COMMODITY_GROUP_code COMMODITY_GROUP
SOURCE_DESC SECTOR_DESC GROUP_DESC COMMODITY_DESC
CLASS_DESC PRODN_PRACTICE_DESC UTIL_PRACTICE_DESC
STATISTICCAT_DESC UNIT_DESC
STATE_FIPS_CODE STATE_NAME
YEAR;
run;
data PRICES_US_3;
retain Merge_US_price;
merge PRICES_US_Annual_2(in=b) PRICES_US_Month_2(in=a);
by AGG_LEVEL_DESC
COMMODITY_GROUP_code COMMODITY_GROUP
SOURCE_DESC SECTOR_DESC GROUP_DESC COMMODITY_DESC
CLASS_DESC PRODN_PRACTICE_DESC UTIL_PRACTICE_DESC
STATISTICCAT_DESC UNIT_DESC
STATE_FIPS_CODE STATE_NAME
YEAR;
if a and b then Merge_US_price='Annual and Monthly'; else
if a then Merge_US_price='Annual'; else
if b then Merge_US_price='Monthly';
run;
proc freq data=PRICES_US_3; table Merge_US_price; run;
data PRICES_US_4;
set PRICES_US_3;
JD_PRICES_N= N(of Price_JAN, Price_FEB, Price_MAR,
Price_APR, Price_MAY, Price_JUN,
Price_JUL, Price_AUG, Price_SEP,
Price_OCT, Price_NOV, Price_DEC);
if JD_PRICES_N>3 then
JD_PRICES= mean(of Price_JAN, Price_FEB, Price_MAR,
Price_APR, Price_MAY, Price_JUN,
Price_JUL, Price_AUG, Price_SEP,
Price_OCT, Price_NOV, Price_DEC);
proc sort;
by AGG_LEVEL_DESC
COMMODITY_GROUP_code COMMODITY_GROUP
SOURCE_DESC SECTOR_DESC GROUP_DESC COMMODITY_DESC
CLASS_DESC PRODN_PRACTICE_DESC UTIL_PRACTICE_DESC
STATISTICCAT_DESC UNIT_DESC
STATE_FIPS_CODE STATE_NAME YEAR;
run;
data PRICES_US_5(Keep=Merge_US_price
AGG_LEVEL_DESC
COMMODITY_GROUP_code COMMODITY_GROUP
SOURCE_DESC SECTOR_DESC GROUP_DESC COMMODITY_DESC
CLASS_DESC PRODN_PRACTICE_DESC UTIL_PRACTICE_DESC
STATISTICCAT_DESC PRICES_unit
STATE_FIPS_CODE STATE_NAME YEAR
MARKETING_YEAR_PRICES MARKETING_YEAR_PRICES1
MARKETING_YEAR_PRICES2 CALENDER_YEAR_PRICES
JD_PRICES JD_PRICES_N
Price_JAN Price_FEB Price_MAR
Price_APR Price_MAY Price_JUN
Price_JUL Price_AUG Price_SEP
Price_OCT Price_NOV Price_DEC);
retain Merge_US_price
AGG_LEVEL_DESC
COMMODITY_GROUP_code COMMODITY_GROUP
SOURCE_DESC SECTOR_DESC GROUP_DESC COMMODITY_DESC
CLASS_DESC PRODN_PRACTICE_DESC UTIL_PRACTICE_DESC
STATISTICCAT_DESC PRICES_unit
STATE_FIPS_CODE STATE_NAME YEAR
MARKETING_YEAR_PRICES MARKETING_YEAR_PRICES1
MARKETING_YEAR_PRICES2 CALENDER_YEAR_PRICES
JD_PRICES JD_PRICES_N
Price_JAN Price_FEB Price_MAR
Price_APR Price_MAY Price_JUN
Price_JUL Price_AUG Price_SEP
Price_OCT Price_NOV Price_DEC;
set PRICES_US_4;
if MARKETING_YEAR_PRICES = . then
MARKETING_YEAR_PRICES1=CALENDER_YEAR_PRICES; else
MARKETING_YEAR_PRICES1=MARKETING_YEAR_PRICES;
if MARKETING_YEAR_PRICES1 = . then
MARKETING_YEAR_PRICES2=JD_PRICES; else
MARKETING_YEAR_PRICES2=MARKETING_YEAR_PRICES1;
PRICES_unit=UNIT_DESC;
proc sort;
by AGG_LEVEL_DESC
COMMODITY_GROUP_code COMMODITY_GROUP
SOURCE_DESC SECTOR_DESC GROUP_DESC COMMODITY_DESC
CLASS_DESC PRODN_PRACTICE_DESC UTIL_PRACTICE_DESC
STATISTICCAT_DESC PRICES_unit
STATE_FIPS_CODE STATE_NAME YEAR;
run;
data PRICES_US_6(Keep=Merge_US_price
AGG_LEVEL_DESC
COMMODITY_GROUP_code COMMODITY_GROUP
SOURCE_DESC SECTOR_DESC GROUP_DESC COMMODITY_DESC
CLASS_DESC PRODN_PRACTICE_DESC UTIL_PRACTICE_DESC
STATISTICCAT_DESC PRICES_unit
STATE_FIPS_CODE STATE_NAME YEAR
MARKETING_YEAR_PRICES MARKETING_YEAR_PRICES1
MARKETING_YEAR_PRICES2);
set PRICES_US_5;
proc sort;
by AGG_LEVEL_DESC
COMMODITY_GROUP_code COMMODITY_GROUP
SOURCE_DESC SECTOR_DESC GROUP_DESC COMMODITY_DESC
CLASS_DESC PRODN_PRACTICE_DESC UTIL_PRACTICE_DESC
STATISTICCAT_DESC PRICES_unit
STATE_FIPS_CODE STATE_NAME YEAR;
run;
data PRICES_US_7(Keep=Merge_US_price
AGG_LEVEL_DESC
COMMODITY_GROUP_code COMMODITY_GROUP
SOURCE_DESC SECTOR_DESC GROUP_DESC COMMODITY_DESC
CLASS_DESC PRODN_PRACTICE_DESC UTIL_PRACTICE_DESC
STATISTICCAT_DESC PRICES_unit
STATE_FIPS_CODE STATE_NAME YEAR
MARKETING_YEAR_PRICES MARKETING_YEAR_PRICES1
MARKETING_YEAR_PRICES2);
set PRICES_US_6;
proc sort;
by AGG_LEVEL_DESC
COMMODITY_GROUP_code COMMODITY_GROUP
SOURCE_DESC SECTOR_DESC GROUP_DESC COMMODITY_DESC
CLASS_DESC PRODN_PRACTICE_DESC UTIL_PRACTICE_DESC
STATISTICCAT_DESC PRICES_unit
STATE_FIPS_CODE STATE_NAME YEAR;
run;
data PRICES_US_8(Keep=Merge_US_price
COMMODITY_GROUP_code COMMODITY_GROUP
SOURCE_DESC SECTOR_DESC GROUP_DESC COMMODITY_DESC
CLASS_DESC UTIL_PRACTICE_DESC
YEAR PRICES_unit_us
MARKETING_YEAR_PRICES_US MARKETING_YEAR_PRICES1_US
MARKETING_YEAR_PRICES2_US);
set PRICES_US_7;
PRICES_unit_us=PRICES_unit;
MARKETING_YEAR_PRICES_US=MARKETING_YEAR_PRICES;
MARKETING_YEAR_PRICES1_US=MARKETING_YEAR_PRICES1;
MARKETING_YEAR_PRICES2_US=MARKETING_YEAR_PRICES2;
proc sort;
by COMMODITY_GROUP_code COMMODITY_GROUP
SOURCE_DESC SECTOR_DESC GROUP_DESC COMMODITY_DESC
CLASS_DESC UTIL_PRACTICE_DESC
YEAR;
run;
/*************************************************************/
/*************************************************************/
/*
proc sql;
create table PRICES_USST_7a as
select *, coalesce(PRICES_ST_7a.groupID, PRICES_US_7a.groupID) as USSTid
from PRICES_ST_7a full join PRICES_US_7a on
PRICES_ST_7a.groupID=PRICES_US_7a.groupID;
quit;
*/
/*************************************************************/
/*************************************************************/
data COUNTY_PRODUCTION_1;
set COUNTY_PRODUCTION;
proc sort;
by COMMODITY_GROUP_code COMMODITY_GROUP
SOURCE_DESC SECTOR_DESC GROUP_DESC COMMODITY_DESC
CLASS_DESC UTIL_PRACTICE_DESC
STATE_FIPS_CODE STATE_NAME YEAR;
run;
data COUNTY_REVENUE;
retain Merge_cost;
merge COUNTY_PRODUCTION_1(in=a) PRICES_ST_8(in=b);
by COMMODITY_GROUP_code COMMODITY_GROUP
SOURCE_DESC SECTOR_DESC GROUP_DESC COMMODITY_DESC
CLASS_DESC UTIL_PRACTICE_DESC
STATE_FIPS_CODE STATE_NAME YEAR;
if a and b then Merge_cost='CO_production and ST_prices';
else if a then Merge_cost='CO_production';
else if b then Merge_cost='ST_prices';
run;
proc freq data=COUNTY_REVENUE; table Merge_cost; run;
data COUNTY_REVENUE_1;
set COUNTY_REVENUE;
where Merge_cost IN ('CO_production and ST_prices',
'CO_production');
run;
data COUNTY_REVENUE_A;
retain Merge_costrev;
merge COUNTY_REVENUE(in=a) REVENUE_ST_1(in=b);
by COMMODITY_GROUP_code COMMODITY_GROUP
SOURCE_DESC SECTOR_DESC GROUP_DESC COMMODITY_DESC
CLASS_DESC UTIL_PRACTICE_DESC
STATE_FIPS_CODE STATE_NAME YEAR;
if a and b then Merge_costrev='CO_production and ST_revenue';
else if a then Merge_costrev='CO_production';
else if b then Merge_costrev='ST_ST_revenue';
run;
proc freq data=COUNTY_REVENUE_A; table Merge_costrev; run;
data COUNTY_REVENUE_1;
set COUNTY_REVENUE_A;
where Merge_cost IN ('CO_production and ST_revenue',
'CO_production');
proc sort;
by COMMODITY_GROUP_code COMMODITY_GROUP
SOURCE_DESC SECTOR_DESC GROUP_DESC COMMODITY_DESC
CLASS_DESC UTIL_PRACTICE_DESC
YEAR;
run;
data COUNTY_REVENUE_2;
retain Merge_cous Merge_cost;
merge COUNTY_REVENUE_1(in=a) PRICES_US_8(in=b);
by COMMODITY_GROUP_code COMMODITY_GROUP
SOURCE_DESC SECTOR_DESC GROUP_DESC COMMODITY_DESC
CLASS_DESC UTIL_PRACTICE_DESC
YEAR;
if a and b then Merge_cous='CO_production and US_prices';
else if a then Merge_cous='CO_production';
else if b then Merge_cous='US_prices';
run;
data COUNTY_REVENUE_3;
set COUNTY_REVENUE_2;
where Merge_cous IN ('CO_production and US_prices',
'CO_production');
run;
data COUNTY_REVENUE_4(keep=Merge_cous Merge_cost
Merge_ST_price Merge_US_price
AGG_LEVEL_DESC
COMMODITY_GROUP COMMODITY_GROUP_CODE
SOURCE_DESC SECTOR_DESC GROUP_DESC
COMMODITY_DESC CLASS_DESC PRODN_PRACTICE_DESC
UTIL_PRACTICE_DESC STATISTICCAT_DESC SHORT_DESC
STATE_ANSI STATE_FIPS_CODE STATE_ALPHA STATE_NAME
ASD_CODE ASD_DESC COUNTY_ANSI COUNTY_CODE COUNTY_NAME
LOCATION_DESC YEAR FREQ_DESC REFERENCE_PERIOD_DESC
VALUE1 UNIT_DESC MARKETING_YEAR_PRICES2 PRICES_unit_st
MARKETING_YEAR_PRICES2_US PRICES_unit_us
REVENUE_unit_st REVENUE_st);
retain Merge_cous Merge_cost
Merge_ST_price Merge_US_price
AGG_LEVEL_DESC
COMMODITY_GROUP COMMODITY_GROUP_CODE
SOURCE_DESC SECTOR_DESC GROUP_DESC
COMMODITY_DESC CLASS_DESC PRODN_PRACTICE_DESC
UTIL_PRACTICE_DESC STATISTICCAT_DESC SHORT_DESC
STATE_ANSI STATE_FIPS_CODE STATE_ALPHA STATE_NAME
ASD_CODE ASD_DESC COUNTY_ANSI COUNTY_CODE COUNTY_NAME
LOCATION_DESC YEAR FREQ_DESC REFERENCE_PERIOD_DESC
VALUE1 UNIT_DESC MARKETING_YEAR_PRICES2 PRICES_unit_st
MARKETING_YEAR_PRICES2_US PRICES_unit_us
REVENUE_unit_st REVENUE_st;
set COUNTY_REVENUE_3;
proc sort;
by AGG_LEVEL_DESC
COMMODITY_GROUP COMMODITY_GROUP_CODE
SOURCE_DESC SECTOR_DESC GROUP_DESC
COMMODITY_DESC CLASS_DESC PRODN_PRACTICE_DESC
UTIL_PRACTICE_DESC STATISTICCAT_DESC SHORT_DESC
STATE_ANSI STATE_FIPS_CODE STATE_ALPHA STATE_NAME
ASD_CODE ASD_DESC COUNTY_ANSI COUNTY_CODE COUNTY_NAME
LOCATION_DESC YEAR FREQ_DESC REFERENCE_PERIOD_DESC;
run;
/*
proc freq data=COUNTY_REVENUE_4;
table COMMODITY_DESC*(UNIT_DESC CLASS_DESC PRODN_PRACTICE_DESC UTIL_PRACTICE_DESC)/norow nocol nocum nopercent out=FreqCount outexpect sparse;
run;
proc freq data=COUNTY_REVENUE_4;
table COMMODITY_DESC*PRICES_unit_st/norow nocol nocum nopercent out=FreqCount_1 outexpect sparse;
run;
proc freq data=COUNTY_REVENUE_4;
table (COMMODITY_DESC CLASS_DESC PRODN_PRACTICE_DESC UTIL_PRACTICE_DESC)*PRICES_unit_st/norow nocol nocum nopercent out=FreqCount_1 outexpect sparse;
run;
proc freq data=COUNTY_REVENUE_4;
table COUNTY_CODE*COMMODITY_DESC/norow nocol nocum nopercent out=FreqCount outexpect sparse;
run;
proc means data=COUNTY_REVENUE_4 mean noprint;
class COMMODITY_DESC CLASS_DESC PRODN_PRACTICE_DESC UTIL_PRACTICE_DESC Merge_cous YEAR COUNTY_ANSI;
types () COMMODITY_DESC*CLASS_DESC*PRODN_PRACTICE_DESC*UTIL_PRACTICE_DESC*Merge_cous*YEAR*COUNTY_ANSI;
var MARKETING_YEAR_PRICES2 MARKETING_YEAR_PRICES2_US;
output out=sumstat;
run;
data sumstat_a; set sumstat; where _STAT_='MEAN';run;
*/
/*************************************************************/
/*************************************************************/
data COUNTY_REVENUE_5 COUNTY_REVENUE_5_998;
set COUNTY_REVENUE_4;
if COMMODITY_DESC IN ('SORGHUM') then
REVENUE=(VALUE1/1.786)*MARKETING_YEAR_PRICES2; else
if COMMODITY_DESC IN ('SUNFLOWER', 'CANOLA', 'SAFFLOWER') then
REVENUE=(VALUE1/100)*MARKETING_YEAR_PRICES2; else
if COMMODITY_DESC IN ('COTTON') then
REVENUE=(VALUE1*480)*MARKETING_YEAR_PRICES2; else
REVENUE=(VALUE1)*MARKETING_YEAR_PRICES2;
if COUNTY_CODE=998 then output COUNTY_REVENUE_5_998;
else output COUNTY_REVENUE_5;
run;
data COUNTY_REVENUE_5_check;
set COUNTY_REVENUE_5;
where COMMODITY_DESC IN ('SORGHUM', 'SUNFLOWER',
'CANOLA', 'SAFFLOWER', 'COTTON');
run;
/*************************************************************/
/*************************************************************/
/********************************************************/
/********************************************************/
data NASS2.Step1_PRICES_US_ST; set PRICES_8; run;
data NASS2.Step1_COUNTY_REVENUE; set COUNTY_REVENUE; run;
/********************************************************/
/********************************************************/
/* Stop timer */
data _null_;
dur = datetime() - &_timer_start;
put 30*'-' / ' TOTAL DURATION:' dur time13.2 / 30*'-';
run;