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!!!!
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.