<?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: transform all numeric varaibles into their formatted values in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/transform-all-numeric-varaibles-into-their-formatted-values/m-p/747848#M234805</link>
    <description>&lt;P&gt;You have 500 numeric variables, and you want 500 character variables that are the numeric variables formatted. This seems redundant.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would start by questioning the need for this. Because the simplest way to do this is to use the numeric variables, formatted, and not create the character variables. How simple is that?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What will you do with the character variables that you cannot do with formatted numeric variables?&lt;/P&gt;</description>
    <pubDate>Mon, 14 Jun 2021 15:43:31 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2021-06-14T15:43:31Z</dc:date>
    <item>
      <title>transform all numeric varaibles into their formatted values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/transform-all-numeric-varaibles-into-their-formatted-values/m-p/747821#M234787</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;Let's say that I have a data set with many varaibles X1,X2.....X500.&lt;/P&gt;
&lt;P&gt;Let's say that each varaible is numeric with format.&lt;/P&gt;
&lt;P&gt;I want to transform each varaible (numeric) into char varaible that will get the formatted values.&lt;/P&gt;
&lt;P&gt;I know to do it manually:&lt;/P&gt;
&lt;P&gt;x1_char=put(x1,f1ff.);&lt;/P&gt;
&lt;P&gt;X2_char=put(x2,agefmt.);&lt;/P&gt;
&lt;P&gt;X3_char=put(X3, wealthFmt.);&lt;/P&gt;
&lt;P&gt;and so on&lt;/P&gt;
&lt;P&gt;The problem is that I have 500 varaibles and it is not a clever way to write this statement for each varaible.&lt;/P&gt;
&lt;P&gt;My question:&lt;/P&gt;
&lt;P&gt;What is the way to transform all numeric varaibles into their formatted values in a quick clever way?&lt;/P&gt;</description>
      <pubDate>Mon, 14 Jun 2021 14:34:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/transform-all-numeric-varaibles-into-their-formatted-values/m-p/747821#M234787</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2021-06-14T14:34:59Z</dc:date>
    </item>
    <item>
      <title>Re: transform all numeric varaibles into their formatted values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/transform-all-numeric-varaibles-into-their-formatted-values/m-p/747832#M234795</link>
      <description>&lt;P&gt;I would probably use a macro to generate the put statements.&amp;nbsp; The macro would iterate through the dataset definition, obtain the varname and format, then %PUT the put statement.&amp;nbsp; You would put the macro inline; in other words, it would be used within a Data step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jim&lt;/P&gt;</description>
      <pubDate>Mon, 14 Jun 2021 14:56:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/transform-all-numeric-varaibles-into-their-formatted-values/m-p/747832#M234795</guid>
      <dc:creator>jimbarbour</dc:creator>
      <dc:date>2021-06-14T14:56:44Z</dc:date>
    </item>
    <item>
      <title>Re: transform all numeric varaibles into their formatted values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/transform-all-numeric-varaibles-into-their-formatted-values/m-p/747837#M234799</link>
      <description>May you show a code?&lt;BR /&gt;Thank you</description>
      <pubDate>Mon, 14 Jun 2021 15:03:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/transform-all-numeric-varaibles-into-their-formatted-values/m-p/747837#M234799</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2021-06-14T15:03:12Z</dc:date>
    </item>
    <item>
      <title>Re: transform all numeric varaibles into their formatted values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/transform-all-numeric-varaibles-into-their-formatted-values/m-p/747839#M234800</link>
      <description>&lt;P&gt;Yes,&amp;nbsp; I could write something up, but actually as I think about it, I think it might be simpler to use VVALUE().&amp;nbsp; Give me a minute.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jim&lt;/P&gt;</description>
      <pubDate>Mon, 14 Jun 2021 15:38:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/transform-all-numeric-varaibles-into-their-formatted-values/m-p/747839#M234800</guid>
      <dc:creator>jimbarbour</dc:creator>
      <dc:date>2021-06-14T15:38:51Z</dc:date>
    </item>
    <item>
      <title>Re: transform all numeric varaibles into their formatted values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/transform-all-numeric-varaibles-into-their-formatted-values/m-p/747841#M234802</link>
      <description>&lt;P&gt;There are many ways to do this, but since the formatting information is stored in SASHELP.VCOLUMN, I think it is easier to store it in a macro variable and have it processed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  format x1 z6.
         x2 date9.
         x3 dollar12.2
         x4 time5.
         x5 datetime16.;
  array x{5};
  do i=1 to 5;
    x{i}=10000;
  end;
  drop i;
run;
data _null_;
  set sashelp.vcolumn;
  where libname='WORK' and memname='HAVE';
  call symputx(cats('fmt',_n_),format);/* format to macro variable */
  call symputx(cats('name',_n_),name);/* variable name to macro variable */
  call symputx('nobs',_n_);/* loop count */
run;

%Macro Mtransform;
  data want;
    set have;
    length char1-char5 $200;
    %do i=1 %to &amp;amp;nobs;
      char&amp;amp;i=putn(&amp;amp;&amp;amp;name&amp;amp;i,"&amp;amp;&amp;amp;fmt&amp;amp;i");
    %end;
  run;
%Mend;
%Mtransform;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 14 Jun 2021 15:14:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/transform-all-numeric-varaibles-into-their-formatted-values/m-p/747841#M234802</guid>
      <dc:creator>japelin</dc:creator>
      <dc:date>2021-06-14T15:14:32Z</dc:date>
    </item>
    <item>
      <title>Re: transform all numeric varaibles into their formatted values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/transform-all-numeric-varaibles-into-their-formatted-values/m-p/747846#M234804</link>
      <description>&lt;P&gt;Something like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA	Have;
	FORMAT	X1	DATE9.;
	FORMAT	X2	COMMA17.;
	FORMAT	X3	PERCENT8.2;

	INPUT	X1
			X2
			X3
			;

DATALINES;
22443  123456789  .9875
22444  999999999  .882
22445  100000000  .628
RUN;

PROC	CONTENTS	DATA=Have	
	OUT=Have_Columns	(KEEP=Name);
RUN;

DATA	_NULL_;
	SET	Have_Columns;
	CALL	SYMPUTX(CATS('VarName',PUT(_N_,8.)), Name, 'G');
	CALL	SYMPUTX('Nbr_of_Vars', PUT(_N_,8.), 'G');
RUN;

%MACRO	Create_Formatted_Char_Vars;
	%LOCAL	i;
	%DO	i	=	1	%TO	&amp;amp;Nbr_Of_Vars;
		%SYSFUNC(CATS(Char_, &amp;amp;&amp;amp;VarName&amp;amp;i)) = VVALUE(&amp;amp;&amp;amp;VarName&amp;amp;i);
	%END;
%MEND	Create_Formatted_Char_Vars;

DATA	Want;
	SET	Have;
	%Create_Formatted_Char_Vars;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Which creates the below.&amp;nbsp; Notice that the second three columns have the same values as the formatted first three columns&amp;nbsp;&lt;STRONG&gt;but&lt;/STRONG&gt; that the last three columns are character.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jimbarbour_0-1623685008593.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/60351iFC0AFCF46381A45E/image-size/medium?v=v2&amp;amp;px=400" role="button" title="jimbarbour_0-1623685008593.png" alt="jimbarbour_0-1623685008593.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Jim&lt;/P&gt;</description>
      <pubDate>Mon, 14 Jun 2021 15:38:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/transform-all-numeric-varaibles-into-their-formatted-values/m-p/747846#M234804</guid>
      <dc:creator>jimbarbour</dc:creator>
      <dc:date>2021-06-14T15:38:02Z</dc:date>
    </item>
    <item>
      <title>Re: transform all numeric varaibles into their formatted values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/transform-all-numeric-varaibles-into-their-formatted-values/m-p/747848#M234805</link>
      <description>&lt;P&gt;You have 500 numeric variables, and you want 500 character variables that are the numeric variables formatted. This seems redundant.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would start by questioning the need for this. Because the simplest way to do this is to use the numeric variables, formatted, and not create the character variables. How simple is that?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What will you do with the character variables that you cannot do with formatted numeric variables?&lt;/P&gt;</description>
      <pubDate>Mon, 14 Jun 2021 15:43:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/transform-all-numeric-varaibles-into-their-formatted-values/m-p/747848#M234805</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-06-14T15:43:31Z</dc:date>
    </item>
  </channel>
</rss>

