BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Brownisiak69
Fluorite | Level 6

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?

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

[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;

 

View solution in original post

7 REPLIES 7
AMSAS
SAS Super FREQ

You are probably looking for a format 

 

Possibly something like PERCENTw.d Format 

ballardw
Super User

[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;

 

Brownisiak69
Fluorite | Level 6
As tried the query provided by you worked successfully, much more thanks for your help and support.
Kurt_Bremser
Super User

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.

Brownisiak69
Fluorite | Level 6

Capture2.2.PNG

If I use format percent7.2, this type of error message shows

 

Tom
Super User Tom
Super User

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.

Brownisiak69
Fluorite | Level 6
Yes, I get the result. The length statement hold my program, so I removed the length statement and added the format statement and got the result.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 7 replies
  • 715 views
  • 2 likes
  • 5 in conversation