<?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: keep the formated value instead of original value from a dataset. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/keep-the-formated-value-instead-of-original-value-from-a-dataset/m-p/984990#M379775</link>
    <description>&lt;P&gt;You need to resort to the function VVALUE().&lt;/P&gt;
&lt;P&gt;Here is an example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc format;
value a
1='a'
2='b'
;
value b
1='xxx'
2='yyy'
;
run;


data have;
input a b;
format a a. b b.;
cards;
1 2
2 2
1 1
;

data want;
 set have;
 array x{*} a b;
 array y{*} $ 40 v1 v2;
 do i=1 to dim(x);
   y{i}=&lt;STRONG&gt;vvalue&lt;/STRONG&gt;(x{i});
 end;
 run;&lt;/PRE&gt;</description>
    <pubDate>Thu, 19 Mar 2026 06:19:24 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2026-03-19T06:19:24Z</dc:date>
    <item>
      <title>keep the formated value instead of original value from a dataset.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/keep-the-formated-value-instead-of-original-value-from-a-dataset/m-p/984936#M379770</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i am wondering if there is a simple way to&amp;nbsp;keep the formated value instead of original value from a dataset.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;for example if have a dataset "A" with many formatted vars inside,&amp;nbsp; i want to keep their formatted value instead of the formatted value in a dataset, its a pain to do "new_var=put(var, $format.);"&amp;nbsp; for every var.&lt;/P&gt;</description>
      <pubDate>Wed, 18 Mar 2026 11:10:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/keep-the-formated-value-instead-of-original-value-from-a-dataset/m-p/984936#M379770</guid>
      <dc:creator>TK12</dc:creator>
      <dc:date>2026-03-18T11:10:44Z</dc:date>
    </item>
    <item>
      <title>Re: keep the formated value instead of original value from a dataset.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/keep-the-formated-value-instead-of-original-value-from-a-dataset/m-p/984938#M379771</link>
      <description>&lt;P&gt;I suppose you could create a macro that loops through all variables and does this PUT command. But even then there are problems, if the variable is numeric, you can't replace the original numeric value with a character value, you would have to create a new character variable (with a different name). If you have a character variable, then PUT would work but if the length of the formatted value is longer than the length of the unformatted value, the formatted value will get truncated. So, a somewhat complicated macro is needed that will handle these (and possibly other) situations.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could do a similar thing with ARRAY.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;May I ask why this is necessary? I have a feeling that if we knew why you want to do something like this, we might be able to figure out a better approach.&lt;/P&gt;</description>
      <pubDate>Wed, 18 Mar 2026 12:03:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/keep-the-formated-value-instead-of-original-value-from-a-dataset/m-p/984938#M379771</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2026-03-18T12:03:22Z</dc:date>
    </item>
    <item>
      <title>Re: keep the formated value instead of original value from a dataset.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/keep-the-formated-value-instead-of-original-value-from-a-dataset/m-p/984948#M379772</link>
      <description>&lt;P&gt;As&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;suggested, you could use macro logic to do this. If the formats are permanently assigned in a DATA step, then you can use an output data set from PROC CONTENTS to build your statements. I have included an example below.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
 value $gen 'M'='Male' 'F'='Female';
run;

data class;
set sashelp.class;
format sex $gen. height weight dollar12.2;
run;

ods output variables=out(where=(format ne ' '));

proc contents data=class ;
run;

proc print data=out;
run;

data _null_;
set out;
by variable;
if first.variable then do;
 call symputx('varname'||left(_n_),variable);
 call symputx('fmt'||left(_n_),format);
end;
call symputx('total',_n_);
run;

%put _user_;

%macro loop;

data class1;
set class;
%do i=1 %to &amp;amp;total;
new_&amp;amp;&amp;amp;varname&amp;amp;i=put(&amp;amp;&amp;amp;varname&amp;amp;i,&amp;amp;&amp;amp;fmt&amp;amp;i);
%end;
run;

proc print data=class1;
run;

proc contents data=class1;
run;

%mend;
%loop&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 18 Mar 2026 13:57:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/keep-the-formated-value-instead-of-original-value-from-a-dataset/m-p/984948#M379772</guid>
      <dc:creator>Kathryn_SAS</dc:creator>
      <dc:date>2026-03-18T13:57:12Z</dc:date>
    </item>
    <item>
      <title>Re: keep the formated value instead of original value from a dataset.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/keep-the-formated-value-instead-of-original-value-from-a-dataset/m-p/984959#M379773</link>
      <description>&lt;P&gt;You could write the data set to file and then use PROC IMPORT to read it back in as all character.&amp;nbsp; Write two name rows forces all columns to character.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc contents varnum data=sashelp.demographics;
   run;
filename FT72F001 temp;
data _null_;
   file FT72F001 dsd;
   *file log;
   set sashelp.demographics(obs=40);
   if _n_ eq 1 then link namerow;
   put (_all_)(:);
   return;
   /*Write name row twice */
namerow:
   length __NAME $32; 
   do _n_ = 1 to 2;
      call missing(__NAME);
      do until(missing(__name));
         call vnext(__name);
         if __name eq: '__' then leave;
         if not missing(__name) then put __name @;
         end;
      put;
      end; 
   return;
   run;

proc import file=FT72F001 dbms=csv out=allchar;
   run;
proc contents varnum data=allchar;
   run;

proc print data=allchar(obs=10);
   run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot 2026-03-18 101537.png" style="width: 302px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/113684iFD81FDF8CD4C3667/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screenshot 2026-03-18 101537.png" alt="Screenshot 2026-03-18 101537.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I updated the code to use&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;suggestion to quote the values using ~ format modifier.&amp;nbsp; Also, use _TEMPORARY_ array to hold variable name returned from CALL VNEXT.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc contents varnum data=sashelp.demographics;
   run;
proc print data=sashelp.demographics(obs=40);
   run;
filename FT72F001 temp;
data _null_;
   file FT72F001 dsd;
   *file log dsd;
   set sashelp.demographics(obs=40);
   if _n_ eq 1 then link namerow;
   put (_all_)(~);
   return;
namerow:
   array __Name [1] $32 _temporary_;
   do until(missing(__name[1]));
      call vnext(__name[1]);
      if __name[1] eq: '_ERROR' then leave; /*When vnext is _ERROR_*/
      if not missing(__name[1]) then put __name[1] @;
      end;
   put;
   return;
   run;
proc import file=FT72F001 dbms=csv out=allchar replace;
   run;

proc contents varnum data=allchar;
   run;
proc print data=allchar(obs=10);
   run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 19 Mar 2026 13:50:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/keep-the-formated-value-instead-of-original-value-from-a-dataset/m-p/984959#M379773</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2026-03-19T13:50:42Z</dc:date>
    </item>
    <item>
      <title>Re: keep the formated value instead of original value from a dataset.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/keep-the-formated-value-instead-of-original-value-from-a-dataset/m-p/984971#M379774</link>
      <description>&lt;P&gt;Actually you can take advantage of a quirk of PROC IMPORT.&amp;nbsp; If it sees that all observations of a variable are quoted it decides the variable must be character.&amp;nbsp; So use the ~ modifier to write a CSV file where everything is quoted (whether the value needs quotes or not).&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let dsn=sashelp.cars;
filename csv temp;

* Write header row ;
proc transpose data=&amp;amp;dsn(obs=0) out=names ;
 var _all_;
run;
data _null_;
  file csv dsd ;
  set names;
  put _name_ ~ @ ;
run;
* Appedn data rows ;
data _null_;
  file csv dsd mod ;
  set &amp;amp;dsn ;
  put (_all_) (~);
run;

proc import dbms=csv file=csv out=want replace;
run;

proc contents data=want varnum;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;DIV id="tinyMceEditorTom_0" class="mceNonEditable lia-copypaste-placeholder"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV id="tinyMceEditorTom_5" class="mceNonEditable lia-copypaste-placeholder"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV id="tinyMceEditorTom_0" class="mceNonEditable lia-copypaste-placeholder"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot 2026-03-18 at 12.36.03 PM.png" style="width: 522px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/113690i3B7F706C784B010B/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screenshot 2026-03-18 at 12.36.03 PM.png" alt="Screenshot 2026-03-18 at 12.36.03 PM.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;DIV id="tinyMceEditorTom_4" class="mceNonEditable lia-copypaste-placeholder"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV id="tinyMceEditorTom_2" class="mceNonEditable lia-copypaste-placeholder"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV id="tinyMceEditorTom_1" class="mceNonEditable lia-copypaste-placeholder"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV id="tinyMceEditorTom_3" class="mceNonEditable lia-copypaste-placeholder"&gt;&amp;nbsp;&lt;/DIV&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>Wed, 18 Mar 2026 16:36:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/keep-the-formated-value-instead-of-original-value-from-a-dataset/m-p/984971#M379774</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2026-03-18T16:36:26Z</dc:date>
    </item>
    <item>
      <title>Re: keep the formated value instead of original value from a dataset.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/keep-the-formated-value-instead-of-original-value-from-a-dataset/m-p/984990#M379775</link>
      <description>&lt;P&gt;You need to resort to the function VVALUE().&lt;/P&gt;
&lt;P&gt;Here is an example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc format;
value a
1='a'
2='b'
;
value b
1='xxx'
2='yyy'
;
run;


data have;
input a b;
format a a. b b.;
cards;
1 2
2 2
1 1
;

data want;
 set have;
 array x{*} a b;
 array y{*} $ 40 v1 v2;
 do i=1 to dim(x);
   y{i}=&lt;STRONG&gt;vvalue&lt;/STRONG&gt;(x{i});
 end;
 run;&lt;/PRE&gt;</description>
      <pubDate>Thu, 19 Mar 2026 06:19:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/keep-the-formated-value-instead-of-original-value-from-a-dataset/m-p/984990#M379775</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2026-03-19T06:19:24Z</dc:date>
    </item>
  </channel>
</rss>

