DATA XYZ;
SET XYZ_V1;
KEEP DTS COD Q_1 Q_2 Q_3 Q_4 QPC_1 QPC_2 QPC_3 QPC_4 TOTAL_SUM;
LENGTH QPC_1 QPC_2 QPC_3 QPC_4 $6;
QPC_1=Q_1/TOTAL_SUM;
QPC_2=Q_2/TOTAL_SUM;
QPC_3=Q_3/TOTAL_SUM;
QPC_4=Q_4/TOTAL_SUM;
RUN;
HOW DO I GET OUTPUT IN A PECENTAGE FORMAT?
[Admin Note] Added links to format documentation
Percentw.d or PercentNw.d. The Percentw.d format will place () around negative values so reserves two of the positions of the width for those. The PercentNwd. format uses a negative sign, hence the N in the name, for negative values and reserves one position for that.
As an example if you want the format as a default. This only displays one decimal point in the percent.
(Missed the inappropriate definition of variables a character)
DATA XYZ; SET XYZ_V1; KEEP DTS COD Q_1 Q_2 Q_3 Q_4 QPC_1 QPC_2 QPC_3 QPC_4 TOTAL_SUM;LENGTH QPC_1 QPC_2 QPC_3 QPC_4 $6;QPC_1=Q_1/TOTAL_SUM; QPC_2=Q_2/TOTAL_SUM; QPC_3=Q_3/TOTAL_SUM; QPC_4=Q_4/TOTAL_SUM; format Qpc_: percentn8.1; RUN;
[Admin Note] Added links to format documentation
Percentw.d or PercentNw.d. The Percentw.d format will place () around negative values so reserves two of the positions of the width for those. The PercentNwd. format uses a negative sign, hence the N in the name, for negative values and reserves one position for that.
As an example if you want the format as a default. This only displays one decimal point in the percent.
(Missed the inappropriate definition of variables a character)
DATA XYZ; SET XYZ_V1; KEEP DTS COD Q_1 Q_2 Q_3 Q_4 QPC_1 QPC_2 QPC_3 QPC_4 TOTAL_SUM;LENGTH QPC_1 QPC_2 QPC_3 QPC_4 $6;QPC_1=Q_1/TOTAL_SUM; QPC_2=Q_2/TOTAL_SUM; QPC_3=Q_3/TOTAL_SUM; QPC_4=Q_4/TOTAL_SUM; format Qpc_: percentn8.1; RUN;
Why do you define variables which will hold the results of calculations as character?
Remove the LENGTH statement and use a FORMAT statement with PERCENT7.2 instead.
If I use format percent7.2, this type of error message shows
You have to tell the FORMAT statement what variable(s) you want the PERCENT format to be attached to. It cannot read your mind. That is why it is telling you that it is expecting a NAME or a variable list here it has indicated it detected the error.
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.
Ready to level-up your skills? Choose your own adventure.