<?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: vvalue function -Do it for all varaibles in data set in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/vvalue-function-Do-it-for-all-varaibles-in-data-set/m-p/875678#M346003</link>
    <description>&lt;P&gt;Why?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SAS will use the formatted values for analysis, reporting or graphing. So this does not really make much sense.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Export the data to a text file using the formatted values.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Read them back in. Though this step is a waste of time as SAS uses the formats for any purpose that makes sense.&lt;/P&gt;
&lt;P&gt;The Export step creates enough code that it is easy to rename the variables (if that is really important).&lt;/P&gt;</description>
    <pubDate>Sun, 14 May 2023 15:22:40 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2023-05-14T15:22:40Z</dc:date>
    <item>
      <title>vvalue function -Do it for all varaibles in data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/vvalue-function-Do-it-for-all-varaibles-in-data-set/m-p/875674#M345999</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;I have synamic data set .&lt;/P&gt;
&lt;P&gt;It means that in different situations (depends on user macro values) there are different variables in the data set.&lt;/P&gt;
&lt;P&gt;I would like to convert each variable value to its formatted value.&lt;/P&gt;
&lt;P&gt;I saw the way to do it via vvalue function.&lt;/P&gt;
&lt;P&gt;X_=vvalue(X);&lt;/P&gt;
&lt;P&gt;My question:&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#FF0000"&gt;What is the way to perform this conversion to all variables in the data set?&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#FF0000"&gt;I am looking for dynamic code that will do it for each set of variables(because in different situations will have different varaibles)&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;I also want that the converted variables will have same name as the orginal variables.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
value X_Fmt
1='A'
2='B'
;
value Y_Fmt
1='Y'
2='N'
;
Run;

data have;
format x X_Fmt.  y Y_Fmt.;
input ID  X Y W Z;
cards;
1 1 1 1 2
2 1 2 2 2
3 1 1 3 2
4 2 2 3 2
5 2 1 2 1
;
Run;


data want(Drop=X Y W Z rename=(X_=X  Y_=Y  W_=W  Z_=Z));
set have;
X_=vvalue(X);
Y_=vvalue(Y);
W_=vvalue(W);
Z_=vvalue(Z);
Run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 14 May 2023 14:57:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/vvalue-function-Do-it-for-all-varaibles-in-data-set/m-p/875674#M345999</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2023-05-14T14:57:26Z</dc:date>
    </item>
    <item>
      <title>Re: vvalue function -Do it for all varaibles in data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/vvalue-function-Do-it-for-all-varaibles-in-data-set/m-p/875676#M346001</link>
      <description>&lt;P&gt;Use code generation.&lt;/P&gt;
&lt;P&gt;Get the list of variable names. For example using PROC TRANSPOSE.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc transpose data=have(obs=0) out=names ; 
  var _all_;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Use the names to generate the code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  set names end=eof;
  varnum+1;
  length nliteral $60 ;
  nliteral=nliteral(_name_);
  if _n_=1 then call execute('data want; set have;');
  call execute(catx(' ',cats('__',varnum),'=vvalue(',nliteral,');'
      ,'drop',nliteral,';rename',cats('__',varnum),'=',nliteral,';'
  ));
  if eof then call execute('run;');
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results in generated code like this:&lt;/P&gt;
&lt;PRE&gt;1   + data want; set have;
2   + __1 =vvalue( Name ); drop Name ;rename __1 = Name ;
3   + __2 =vvalue( Sex ); drop Sex ;rename __2 = Sex ;
4   + __3 =vvalue( Age ); drop Age ;rename __3 = Age ;
5   + __4 =vvalue( Height ); drop Height ;rename __4 = Height ;
6   + __5 =vvalue( Weight ); drop Weight ;rename __5 = Weight ;
7   + run;
&lt;/PRE&gt;
&lt;P&gt;Getting a reasonable LENGTH for the new character variables is a harder problem.&lt;/P&gt;
&lt;PRE&gt; Variables in Creation Order

#    Variable    Type    Len

1    Name        Char    200
2    Sex         Char    200
3    Age         Char    200
4    Height      Char    200
5    Weight      Char    200
&lt;/PRE&gt;
&lt;P&gt;You might want to do that AFTER converting them, unless some of them need lengths longer than 200.&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>Sun, 14 May 2023 15:08:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/vvalue-function-Do-it-for-all-varaibles-in-data-set/m-p/875676#M346001</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-05-14T15:08:42Z</dc:date>
    </item>
    <item>
      <title>Re: vvalue function -Do it for all varaibles in data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/vvalue-function-Do-it-for-all-varaibles-in-data-set/m-p/875678#M346003</link>
      <description>&lt;P&gt;Why?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SAS will use the formatted values for analysis, reporting or graphing. So this does not really make much sense.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Export the data to a text file using the formatted values.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Read them back in. Though this step is a waste of time as SAS uses the formats for any purpose that makes sense.&lt;/P&gt;
&lt;P&gt;The Export step creates enough code that it is easy to rename the variables (if that is really important).&lt;/P&gt;</description>
      <pubDate>Sun, 14 May 2023 15:22:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/vvalue-function-Do-it-for-all-varaibles-in-data-set/m-p/875678#M346003</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-05-14T15:22:40Z</dc:date>
    </item>
  </channel>
</rss>

