DATA Step, Macro, Functions and more

How to format variable in data step using format name from data set?

Accepted Solution Solved
Reply
Occasional Contributor jb3
Occasional Contributor
Posts: 15
Accepted Solution

How to format variable in data step using format name from data set?

Hi all,

 

I would like to format numeric values (variable "Value" in the SAS code below) in a data step and save the formatted string in a new variable "FormattedValue". The name of the format to use is saved in the data step, too, and can be different for each row of the data set (Variable "FormatString").

 

How can I achieve this? Thanks for your help!

 

Jonas

 

data test;
	input Value FormatString $;
	length FormattedValue $ 64;
	datalines;
		120.5 dollar8.2
		120.1 8.2
		503.6 8.0	
		;
run;

Accepted Solutions
Solution
‎06-09-2016 02:33 AM
Super User
Super User
Posts: 7,070

Re: How to format variable in data step using format name from data set?

Use the PUTN() function.

FormattedValue = putn(Value, FormatString) ;

View solution in original post


All Replies
Solution
‎06-09-2016 02:33 AM
Super User
Super User
Posts: 7,070

Re: How to format variable in data step using format name from data set?

Use the PUTN() function.

FormattedValue = putn(Value, FormatString) ;
Occasional Contributor jb3
Occasional Contributor
Posts: 15

Re: How to format variable in data step using format name from data set?

That was fast, thanks!!
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 217 views
  • 2 likes
  • 2 in conversation