I am using an array to count the number of associates. The value of assoc_nm_2 is formatted as $80. however, when the array is complete it truncates the values of assoc_nm_2 to $8. Is there a way to maintain the length of that variable? I tried a format statement but that bombed.
data nineteen_2 (drop=i j assoc_id_nb assoc_subtyp_cd_2 assoc_nm_2 reg_nb_assoc);
set nineteen;
by PRMRY_BUS_FUNC_NB;
array af_id{%eval(&max_af)} af_id1 - af_id%eval(&max_af);
array af_typ_cd{%eval(&max_af)} af_typ_cd1 - af_typ_cd%eval(&max_af);
array af_nm{%eval(&max_af)} $ af_nm1 - af_nm%eval(&max_af);
array af_reg_nb{%eval(&max_af)} $ af_reg_nb1 - af_reg_nb%eval(&max_af);
retain af_id1 - af_id%eval(&max_af) af_typ_cd1 - af_typ_cd%eval(&max_af) af_nm1 - af_nm%eval(&max_af) af_reg_nb1 - af_reg_nb%eval(&max_af);
if first.PRMRY_BUS_FUNC_NB then do;
i=0;
do j=1 to %eval(&max_af);
af_id(j)=.;
af_typ_cd(j)=.;
af_nm(j)='';
af_reg_nb(j)='';
end;
end;
i+1;
af_id{i}=assoc_id_nb;
af_typ_cd{i}=assoc_subtyp_cd_2;
af_nm{i}=assoc_nm_2;
af_reg_nb{i}=reg_nb_assoc;
if last.PRMRY_BUS_FUNC_NB;
run;
If you don't specify a length I think it defaults to 8.
You can also probably simplify your code as follows - note that I set the array to a length of 12.
You can remove the %eval if you don't have a calculation and use the * to denote length so then SAS determines it automatically based on the list size.
data nineteen_2 (drop=i j assoc_id_nb assoc_subtyp_cd_2 assoc_nm_2 reg_nb_assoc);
set nineteen;
by PRMRY_BUS_FUNC_NB;
array af_id{*} af_id1 - af_id&max_af;
array af_typ_cd{*} af_typ_cd1 - af_typ_cd&max_af;
array af_nm{*} $12 af_nm1 - af_nm&max_af;
array af_reg_nb{*} $12 af_reg_nb1 - af_reg_nb&max_af;
If you don't specify a length I think it defaults to 8.
You can also probably simplify your code as follows - note that I set the array to a length of 12.
You can remove the %eval if you don't have a calculation and use the * to denote length so then SAS determines it automatically based on the list size.
data nineteen_2 (drop=i j assoc_id_nb assoc_subtyp_cd_2 assoc_nm_2 reg_nb_assoc);
set nineteen;
by PRMRY_BUS_FUNC_NB;
array af_id{*} af_id1 - af_id&max_af;
array af_typ_cd{*} af_typ_cd1 - af_typ_cd&max_af;
array af_nm{*} $12 af_nm1 - af_nm&max_af;
array af_reg_nb{*} $12 af_reg_nb1 - af_reg_nb&max_af;
That works perfect! I knew it had to be something simple like that. Thank you for your help!!!!
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.