<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How to get formatted value of variable in its standard format without specifying it? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-formatted-value-of-variable-in-its-standard-format/m-p/608315#M177019</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/243450"&gt;@ADoering&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thanks everyone.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I take it there is no optimal solution (like vvalue() outside data step, or put() with a default), but I like the ideas of&amp;nbsp;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;having views with both formatted and raw values for our main tables&lt;/LI&gt;
&lt;LI&gt;creating a fmt% macro as presented by mkeintz, but combining with unison's suggestion to derive it automatically - since formats are unique to the variable name in that environment accross tables, this shouldn't be an issue - I'll see if I can even combine it with use of vvalue where applicable if not a variable in one of our standard tables. I'd post it when I get to do it - or accept it as a solution, when someone else does &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/LI&gt;
&lt;/UL&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I appreciate the idea of dynamically generating the format, using metadata in the data set header information (or maybe PROC SQL dictionary&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and I wonder whether a DOSUBL macro calling function would be the technique to use.&amp;nbsp; Unlike other uses of macros the it does not need to be resolved prior to execution of the call data step.&amp;nbsp; But I have never needed to find out more about DOSUBL.&amp;nbsp; If someone on this thread could prove or disprove my conjecture, I would be very interested.&lt;/P&gt;</description>
    <pubDate>Fri, 29 Nov 2019 18:36:32 GMT</pubDate>
    <dc:creator>mkeintz</dc:creator>
    <dc:date>2019-11-29T18:36:32Z</dc:date>
    <item>
      <title>How to get formatted value of variable in its standard format without specifying it?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-formatted-value-of-variable-in-its-standard-format/m-p/608031#M176893</link>
      <description>&lt;P&gt;In our work, we are using user defined formats extensively (short codes in the data, long labels in output). Drawback is that for programming/filtering, people still need to remember the raw value behind the formatted value shown otherwise. Of course they could filter for the formatted value by using the put function, only they would need to remember the format name, then, and always specify it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there maybe a more efficient way I'm missing to apply the "standard format" according to the data set definition to the variable in programming without having to specify the format, or otherwise make the formatted value available?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Example:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;/* some user defined format*/ &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;proc format; &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;value companyfmt 1='Company A' 2='Company B' 3='Company C'; &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;run; &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;/* a data set where one variable is formatted using that format */ &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;data test; &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;input company variable $; &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;format company companyfmt.; &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;cards; &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;1 a &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;1 b &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;2 d &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;3 e &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;run; &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;/* to filter, this is what we currently do*/ &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;proc print data=test(where=(company=1)); &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;/* the alternative requires remembering the format name and a lot of typing */ &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;proc print data=test(where=(put(company,companyfmt.)='Company A')); &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;/* ..and this does not work */ &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;proc print data=test(where=(put(company)='Company A')); &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any ideas or best practice appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm on SAS 9.4M5.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks and regards&lt;/P&gt;&lt;P&gt;Andy&lt;/P&gt;</description>
      <pubDate>Thu, 28 Nov 2019 11:46:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-formatted-value-of-variable-in-its-standard-format/m-p/608031#M176893</guid>
      <dc:creator>ADoering</dc:creator>
      <dc:date>2019-11-28T11:46:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to get formatted value of variable in its standard format without specifying it?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-formatted-value-of-variable-in-its-standard-format/m-p/608041#M176896</link>
      <description>&lt;P&gt;Your main issue is "&lt;STRONG&gt;&lt;SPAN&gt;people still need to remember"&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;Are people programmers or users?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do people write their code or import code to adapt to their needs?&lt;/P&gt;
&lt;P&gt;In last case - importing code to adapt - just add format documentation as remarks.&lt;/P&gt;
&lt;P&gt;In more sophisticated tools, like SAS AF, you can use GUI tools to choose from a table.&lt;/P&gt;</description>
      <pubDate>Thu, 28 Nov 2019 12:24:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-formatted-value-of-variable-in-its-standard-format/m-p/608041#M176896</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2019-11-28T12:24:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to get formatted value of variable in its standard format without specifying it?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-formatted-value-of-variable-in-its-standard-format/m-p/608046#M176900</link>
      <description>&lt;P&gt;Try function&amp;nbsp;&amp;nbsp;vvalue() .&lt;/P&gt;</description>
      <pubDate>Thu, 28 Nov 2019 12:54:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-formatted-value-of-variable-in-its-standard-format/m-p/608046#M176900</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2019-11-28T12:54:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to get formatted value of variable in its standard format without specifying it?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-formatted-value-of-variable-in-its-standard-format/m-p/608047#M176901</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Try function&amp;nbsp;&amp;nbsp;vvalue() .&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I thought about something similar, but these functions are only available in data steps, not in where conditions.&lt;/P&gt;</description>
      <pubDate>Thu, 28 Nov 2019 12:58:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-formatted-value-of-variable-in-its-standard-format/m-p/608047#M176901</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-11-28T12:58:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to get formatted value of variable in its standard format without specifying it?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-formatted-value-of-variable-in-its-standard-format/m-p/608051#M176904</link>
      <description>people are actuaries &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; which means they are both (end user programming), while obviously some are power users (frequent programming), others more occasionally programming (more using existing programs where I can use graphic prompts in SAS EG)</description>
      <pubDate>Thu, 28 Nov 2019 13:33:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-formatted-value-of-variable-in-its-standard-format/m-p/608051#M176904</guid>
      <dc:creator>ADoering</dc:creator>
      <dc:date>2019-11-28T13:33:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to get formatted value of variable in its standard format without specifying it?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-formatted-value-of-variable-in-its-standard-format/m-p/608052#M176905</link>
      <description>&lt;P&gt;Sometimes it is wise to apply formats in the reporting procedures only and not on datasets, but this doesn't avoid that users have to remember - in this case - the names of the formats. Depending on the size of the datasets and the number of formatted variables, maybe creating a view having both the formatted and the unformatted version of the variable is an option. By using a view the space on disc should not increase to heavily.&lt;/P&gt;</description>
      <pubDate>Thu, 28 Nov 2019 13:36:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-formatted-value-of-variable-in-its-standard-format/m-p/608052#M176905</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2019-11-28T13:36:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to get formatted value of variable in its standard format without specifying it?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-formatted-value-of-variable-in-its-standard-format/m-p/608053#M176906</link>
      <description>&lt;P&gt;When you have people working together, you only need three things:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Documentation&lt;/LI&gt;
&lt;LI&gt;Documentation&lt;/LI&gt;
&lt;LI&gt;Documentation&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;and a culture that makes use of those.&lt;/P&gt;</description>
      <pubDate>Thu, 28 Nov 2019 13:37:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-formatted-value-of-variable-in-its-standard-format/m-p/608053#M176906</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-11-28T13:37:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to get formatted value of variable in its standard format without specifying it?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-formatted-value-of-variable-in-its-standard-format/m-p/608080#M176911</link>
      <description>&lt;P&gt;If there are no more than, say, 200-300 pairs of variables and formats and they don't change frequently, the amount of typing and remembering could be reduced substantially by using keyboard macros (abbreviations) in the Enhanced Editor (or the equivalent SAS EG feature, if any). These could be distributed to the users in a .kmf file.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;P&gt;Menu Tools --&amp;gt; Add Abbreviation...&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="abbrfmt.png" style="width: 455px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/34308iC0EA42BD65467122/image-size/large?v=v2&amp;amp;px=999" role="button" title="abbrfmt.png" alt="abbrfmt.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;So, after typing "put(c" the editor would suggest the insertion shown above (confirm with Return key), where "Company A" could be the most frequently used company name.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This could be made even more convenient by enhancing the keyboard macro (created by adding this abbreviation) with a few cursor navigation and selection commands so that "Company A" would be highlighted automatically and hence could be overwritten immediately with a different company name:&lt;/P&gt;
&lt;P&gt;Menu Tools --&amp;gt; Keyboard Macros --&amp;gt; Macros... --&amp;gt; Edit...&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="kbdmacro.png" style="width: 500px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/34310iAFACEB02B84BC0F2/image-size/large?v=v2&amp;amp;px=999" role="button" title="kbdmacro.png" alt="kbdmacro.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="highlight.png" style="width: 362px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/34313iFE29E115277EB16A/image-size/large?v=v2&amp;amp;px=999" role="button" title="highlight.png" alt="highlight.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Finally, abbreviations for variable names starting with the same letter could be "grouped" together, e.g.:&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;put(c&amp;nbsp; &amp;nbsp;--&amp;gt;&amp;nbsp;put(company,companyfmt.)='Company A'&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;put(cc&amp;nbsp; --&amp;gt;&amp;nbsp;put(country,countryfmt.)='United States'&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;put(ccc&amp;nbsp;--&amp;gt; put(customer,customerfmt.)='Customer X'&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thus, the user can quickly step through the variable names (displayed in the yellow info text) in alphabetical, frequency or any other order just by repeating the first letter (and backwards with the Backspace key!).&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="showabbr.png" style="width: 441px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/34309i9ED3715A7B206F12/image-size/large?v=v2&amp;amp;px=999" role="button" title="showabbr.png" alt="showabbr.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Nov 2019 15:56:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-formatted-value-of-variable-in-its-standard-format/m-p/608080#M176911</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2019-11-28T15:56:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to get formatted value of variable in its standard format without specifying it?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-formatted-value-of-variable-in-its-standard-format/m-p/608087#M176917</link>
      <description>&lt;P&gt;Make a macro that inserts a format according to the variable name.&amp;nbsp; Then your users will have little to remember or type:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* some user defined format*/ 
proc format; 
value companyfmt 1='Company A' 2='Company B' 3='Company C'; 
run; 

%macro fmt(vname);
  %if &amp;amp;vname=company %then put(company,companyfmt.) ; %else
  %if &amp;amp;vname=variable %then put(variable,$1.) ;
%mend;
 
/* a data set where one variable is formatted using that format */ 
data test; 
input company variable $; 
format company companyfmt.; 
put company=;
cards; 
1 a 
1 b 
2 d 
3 e 
run; 

proc print data=test(where=(%fmt(company)='Company A')); 
run; 
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And this macro could be easily updated every time the dataset is revised (i.e. a new format is assigned).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Additional note:&amp;nbsp; You don't need to include every variable in the %fmt macro - just the ones where underlying value doesn't look like the formatted value.&amp;nbsp; Let's say you only have this problem with variable COMPANY.&amp;nbsp; All the other vars just use defaujlt formats, and therefore don't need a PUT function.&amp;nbsp; Then just set the %FMT macro to issue the var name, but no put function&amp;nbsp; (that's the "%ELSE &amp;amp;vname;" statement below:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* some user defined format*/ 
proc format; 
value companyfmt 1='Company A' 2='Company B' 3='Company C'; 
run; 

%macro fmt(vname);
  %if &amp;amp;vname=company %then put(company,companyfmt.) ; %else
  &amp;amp;vname;
%mend;
 
/* a data set where one variable is formatted using that format */ 
data test; 
input company charvar $  numvar; 
format company companyfmt.; 
put (_all_) (=);
cards; 
1 a 101
1 b 102
2 d 103
3 e 104
run; 
proc print data=test(where=(%fmt(numvar)=103 or %fmt(charvar)='b')); 
run; 
proc print data=test(where=(%fmt(company)='Company A')); 
run; 
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Nov 2019 23:03:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-formatted-value-of-variable-in-its-standard-format/m-p/608087#M176917</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2019-11-28T23:03:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to get formatted value of variable in its standard format without specifying it?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-formatted-value-of-variable-in-its-standard-format/m-p/608091#M176921</link>
      <description>&lt;P&gt;You can probably adjust this to be more robust (right now, there are issues if multiple datasets have the same name but different formats).. But here's an idea!&lt;SPAN style="background-color: #eaeaea; white-space: pre;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* some user defined format*/
proc format;
value companyfmt 1='Company A' 2='Company B' 3='Company C';
run;

/* a data set where one variable is formatted using that format */
data test;
input company variable $;
format company companyfmt.;
cards;
1 a
1 b
2 d
3 e
;
run;

*Stores result of var format into global macro var: _stdfmt;
%macro retreivefmt(var);

%global _stdfmt;
%local dsid;

%let dsid = %sysfunc(open(sashelp.vcolumn(where=(name="&amp;amp;var") obs=1)));
%if &amp;amp;dsid %then %do;
	%syscall set(dsid);
	%let rc=%sysfunc(fetchobs(&amp;amp;dsid,1));
	%let _stdfmt = &amp;amp;format;
 	%let dsid = %sysfunc(close(&amp;amp;dsid));
%end;

%put _stdfmt;
%mend;

%retreivefmt(company);
proc print data=test(where=(put(company,&amp;amp;_stdfmt.)='Company A'));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;-unison&lt;/P&gt;</description>
      <pubDate>Thu, 28 Nov 2019 17:10:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-formatted-value-of-variable-in-its-standard-format/m-p/608091#M176921</guid>
      <dc:creator>unison</dc:creator>
      <dc:date>2019-11-28T17:10:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to get formatted value of variable in its standard format without specifying it?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-formatted-value-of-variable-in-its-standard-format/m-p/608226#M176986</link>
      <description>&lt;P&gt;Ha. Kurt,&lt;/P&gt;
&lt;P&gt;Create a view with vvalue() and proc print that view. Does it look good ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* some user defined format*/

proc format;
value companyfmt 1='Company A' 2='Company B' 3='Company C';
run;

 

/* a data set where one variable is formatted using that format */
data test;
input company variable $;
format company companyfmt.;
cards;
1 a
1 b
2 d
3 e
;

data x/view=x;
set test;
id=vvalue(company);
run;

/* the alternative requires remembering the format name and a lot of typing */
proc print data=x(where=(id='Company A'));run;

 &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 29 Nov 2019 11:31:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-formatted-value-of-variable-in-its-standard-format/m-p/608226#M176986</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2019-11-29T11:31:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to get formatted value of variable in its standard format without specifying it?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-formatted-value-of-variable-in-its-standard-format/m-p/608228#M176988</link>
      <description>&lt;P&gt;Thanks everyone.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I take it there is no optimal solution (like vvalue() outside data step, or put() with a default), but I like the ideas of&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;having views with both formatted and raw values for our main tables&lt;/LI&gt;&lt;LI&gt;creating a fmt% macro as presented by mkeintz, but combining with unison's suggestion to derive it automatically - since formats are unique to the variable name in that environment accross tables, this shouldn't be an issue - I'll see if I can even combine it with use of vvalue where applicable if not a variable in one of our standard tables. I'd post it when I get to do it - or accept it as a solution, when someone else does &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;---------------------------&lt;/P&gt;&lt;P&gt;EDIT&lt;/P&gt;&lt;P&gt;---------------------------&lt;/P&gt;&lt;P&gt;This would currently be my solution:&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;%Macro fmt(var);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;%local dsid rc;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;%let dsid = %sysfunc(open(sashelp.vcolumn(where=(upcase(name)=upcase("&amp;amp;var")) obs=1)));&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;%put &amp;amp;dsid;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;%if &amp;amp;dsid %then %do;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;%syscall set(dsid);&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;%let rc=%sysfunc(fetchobs(&amp;amp;dsid,1));&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;%let dsid = %sysfunc(close(&amp;amp;dsid));&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;%end;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;%if not %symexist(format) %then %do;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;amp;var&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;%end; %else %do;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;put(&amp;amp;var, &amp;amp;format)&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;%end;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;%mend;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;/*Test&amp;amp;Examples*/&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;proc format;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;value yesno 0='No' .=' ' other='Yes';&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;run;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;data test;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;format ayesno yesno.;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;input ayesno;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;b=%fmt(ayesno);&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;datalines;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;1&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;0&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;1&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;run;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;proc print data=test(where=(%fmt(ayesno)='No'));&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;run;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;Thanks to mkeintz and in particular to unison for the technique to get the &lt;FONT face="courier new,courier"&gt;&amp;amp;format&lt;/FONT&gt; via &lt;FONT face="courier new,courier"&gt;fetchobs&lt;/FONT&gt; (at least that's where I think &lt;FONT face="courier new,courier"&gt;&amp;amp;format&lt;/FONT&gt; comes from, even though I could not spot anything in respect of return of variables as macro variables in the &lt;FONT face="courier new,courier"&gt;fetchobs&lt;/FONT&gt;-documentation).&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 02 Dec 2019 17:33:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-formatted-value-of-variable-in-its-standard-format/m-p/608228#M176988</guid>
      <dc:creator>ADoering</dc:creator>
      <dc:date>2019-12-02T17:33:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to get formatted value of variable in its standard format without specifying it?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-formatted-value-of-variable-in-its-standard-format/m-p/608291#M177009</link>
      <description>&lt;P&gt;So it looks like you are trying to solve the problem of how to filter the data when you know the formatted value but not the actual value.&lt;/P&gt;
&lt;P&gt;One trick I have seen is to create a copy of your format library where all of your format labels (decoded values) have been converted to include the actual value also.&amp;nbsp; Then users know what value to use in the code.&amp;nbsp; When you are finished with coding/debugging just change the FMTSEARCH option to use the original format library and your reports will look nice again.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Something like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format cat=formats;
  value companyfmt 1='Company A' 2='Company B' 3='Company C';
run;
proc format cat=cformats;
  value companyfmt 1='1 Company A' 2='2 Company B' 3='3 Company C';
run;
* Use the code including formats ;
options fmtsearch=(cformats formats);
proc freq data=test; tables company; run;
* Switch back to using the normal formats ;
options fmtsearch=(formats);
proc freq data=test ;
 tables company ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;It is not that hard to convert an existing format catalog by using PROC FORMAT to convert it to a dataset and then manipulate the dataset to change the labels and use PROC FORMAT to make the new catalog;&lt;/P&gt;</description>
      <pubDate>Fri, 29 Nov 2019 16:50:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-formatted-value-of-variable-in-its-standard-format/m-p/608291#M177009</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-11-29T16:50:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to get formatted value of variable in its standard format without specifying it?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-formatted-value-of-variable-in-its-standard-format/m-p/608315#M177019</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/243450"&gt;@ADoering&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thanks everyone.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I take it there is no optimal solution (like vvalue() outside data step, or put() with a default), but I like the ideas of&amp;nbsp;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;having views with both formatted and raw values for our main tables&lt;/LI&gt;
&lt;LI&gt;creating a fmt% macro as presented by mkeintz, but combining with unison's suggestion to derive it automatically - since formats are unique to the variable name in that environment accross tables, this shouldn't be an issue - I'll see if I can even combine it with use of vvalue where applicable if not a variable in one of our standard tables. I'd post it when I get to do it - or accept it as a solution, when someone else does &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/LI&gt;
&lt;/UL&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I appreciate the idea of dynamically generating the format, using metadata in the data set header information (or maybe PROC SQL dictionary&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and I wonder whether a DOSUBL macro calling function would be the technique to use.&amp;nbsp; Unlike other uses of macros the it does not need to be resolved prior to execution of the call data step.&amp;nbsp; But I have never needed to find out more about DOSUBL.&amp;nbsp; If someone on this thread could prove or disprove my conjecture, I would be very interested.&lt;/P&gt;</description>
      <pubDate>Fri, 29 Nov 2019 18:36:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-formatted-value-of-variable-in-its-standard-format/m-p/608315#M177019</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2019-11-29T18:36:32Z</dc:date>
    </item>
  </channel>
</rss>

