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

I am trying to build a function in SAS that will concatenate and number and a percent value and return a character string result like X (Y%). Here is my code:

 

proc fcmp outlib = func.funcs.mwfunc;
	/* Create function to return a string in the style X (Y%) */
	function npct(n, pct) $ 25;
		length concatp $25 n pct 8;
		n_f = n;
		pct_f = pct;
		concatp = cat(n_f, " (", round(pct_f*100,0.01),"%",")");
		return(concatp);
	endsub;
quit;

/* Test function */
data _null_;
	x = npct(5,0.10);
	put x;
run;

When I test this function, it produces the following result:

5 (10=)

 

Instead of 5 (10%).

 

How do I correct this? Is there some kind of masking function I need?

 

Thanks for the help. I am working in SAS 9.4.

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Just use single quotes.

'%'

in your function definition.

View solution in original post

2 REPLIES 2
Tom
Super User Tom
Super User

Just use single quotes.

'%'

in your function definition.

Martha
Fluorite | Level 6

Thank you, that was way easier than I anticipated!

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

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

View all other training opportunities.

Discussion stats
  • 2 replies
  • 1343 views
  • 4 likes
  • 2 in conversation