宏变量的长度可以用 mvarsize= system option 定义。 但有最大值(65534)限制.
一个数据步中可以用多个label语句。可以考虑按照code的排序用where条件将label的宏变量分成几个长度小于65000的宏
变量。 当然还需要提前估算每一个label的长度。可以根据数据调整下面的code。
- proc sql noprint;
- create table distinct_code as select distinct zip_code
- from code
- order by zip_code;
- select cats("code", monotonic(),"=", "'", zip_code, "'") into: label_1_zip separated by ' '
- from distinct_code
- where zip_code < 50000
- order by zip_code;
- select cats("code", monotonic(),"=", "'", zip_code, "'") into: label_2_zip separated by ' '
- from distinct_code
- where 50000 <= zip_code < 99999
- order by zip_code;
- quit;
array 变量长度 _$15. _$20. _$20. 是大于原数据中的变量长度的(code_$5., city_$10., county_$12.)。测试过如果
用原数据中的变量长度city name 和county name可能会被截断。
建议选则大于proc contents 列出的长度.
3.
把前面的程序改成了只包含两个变量, 主要是最后一个datastep.
- /* vvvvv zip_code ~ city vvvvvvvv */
- proc sql noprint;
- select count(distinct zip_code) into: n_zip from code;
- select max(a.n_city) into: n_city
- from (select count(city) as n_city
- from code
- group by zip_code) as a;
- quit;
- %put the number of distinct zip_Code is: &n_zip;
- %put the maximum number of city for each zip_code is: &n_city;
- proc sort data=code;
- by zip_code;
- run;
- proc sql noprint; /* program to create labels */
- create table distinct_code as select distinct zip_code
- from code
- order by zip_code;
- select cats("code", monotonic(),"=", "'", zip_code, "'") into: label_1_zip separated by ' '
- from distinct_code
- where zip_code < "50000"
- order by zip_code;
- select cats("code", monotonic(),"=", "'", zip_code, "'") into: label_2_zip separated by ' '
- from distinct_code
- where "5000" <= zip_code < "99999"
- order by zip_code;
- quit;
- %put &label_1_zip;
- %put &label_2_zip;
- data code_city;
- array code {&n_zip} $15. ;
- array temp_city{&n_city, &n_zip} $20.;
- set code end=last;
- by zip_code;
- retain temp_city: ;
- retain i_zip 0;
- if first.zip_code then do;
- i_zip + 1; i_city = 1;
- end;
- temp_city[i_city, i_zip]= city;
- i_city + 1;
- if last then do; /* vvvv --- output --- vvvv */
- do k1 = 1 to &n_city;
- do k2 = 1 to &n_zip;
- code[k2] = temp_city[k1,k2];
- end;
- output;
- end;
- end;
- label &label_1_zip;
- label &label_2_zip;
- keep code:;
- run;
- /* ^^^^^ zip_code ~ city ^^^^^ */


雷达卡




京公网安备 11010802022788号







