DATA Step, Macro, Functions and more

Use a dataset to provide the format to an argument for a put statement

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 8
Accepted Solution

Use a dataset to provide the format to an argument for a put statement

I have a data set that looks like this:

 

image.png

 

Where "response" is a formatted column (actual values are numeric: 1,2, 3). I have the correct format in the "format" column, as text. 

 

I would like to do something like

 

 

DATA desired;

    SET current_data;

    question_fmt = put(response, format);

RUN;

Here I want the format supplied to the put argument to come from the format column. IS there a way to do this?


Accepted Solutions
Solution
‎04-26-2018 09:45 AM
Regular Contributor
Posts: 164

Re: Use a dataset to provide the format to an argument for a put statement

Hi,

 

you can use the vvalue function (Returns by Default a $200 length if not specified)

DATA desired;
    SET current_data;
    question_fmt = vvalue(Response);
RUN;
________________________

- Cheers -

View solution in original post


All Replies
Super User
Posts: 10,530

Re: Use a dataset to provide the format to an argument for a put statement

Please post data in a usable form (hint: pictures ar NOT useful). See my footnotes.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Solution
‎04-26-2018 09:45 AM
Regular Contributor
Posts: 164

Re: Use a dataset to provide the format to an argument for a put statement

Hi,

 

you can use the vvalue function (Returns by Default a $200 length if not specified)

DATA desired;
    SET current_data;
    question_fmt = vvalue(Response);
RUN;
________________________

- Cheers -

Occasional Contributor
Posts: 8

Re: Use a dataset to provide the format to an argument for a put statement

[ Edited ]

This is exactly the function I needed

 

Thank you!

Super User
Super User
Posts: 9,799

Re: Use a dataset to provide the format to an argument for a put statement

Post test data in the form of a datastep and what you want to see out.  How are you going to store the output text with the format, as formats apply to the whole variable?  You could use a text field of course.

I suspect what you are after is the putc and putn functions.  Then you pass the variable, the format name, and optionally length across:

http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000212562.htm

☑ This topic is solved.

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

Discussion stats
  • 4 replies
  • 135 views
  • 1 like
  • 4 in conversation