<?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 use 'put' to change data format into charater? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-put-to-change-data-format-into-charater/m-p/368348#M87841</link>
    <description>&lt;P&gt;Depending on what you actually attempt and are going to use the data for&amp;nbsp;be aware that you may need to consider leading blanks in the resulting variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 19 Jun 2017 14:34:54 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2017-06-19T14:34:54Z</dc:date>
    <item>
      <title>How to use 'put' to change data format into charater?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-put-to-change-data-format-into-charater/m-p/368341#M87838</link>
      <description>&lt;P&gt;Hello:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a SAS dataset with 30 variables with date format and 120 variables with numeric formate.&amp;nbsp; I need to change all of them into charterics.&amp;nbsp;&amp;nbsp; Is there a way I could refer them all in once instead of typing them all?&amp;nbsp;&amp;nbsp; This is not one time use.&amp;nbsp; I am expecting I will have more data coming from different sources with different counts of date and numeric variables.&amp;nbsp; I hope I don't need to type them again and again.&amp;nbsp; Thanks.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 19 Jun 2017 14:17:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-put-to-change-data-format-into-charater/m-p/368341#M87838</guid>
      <dc:creator>ybz12003</dc:creator>
      <dc:date>2017-06-19T14:17:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to use 'put' to change data format into charater?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-put-to-change-data-format-into-charater/m-p/368343#M87839</link>
      <description>&lt;P&gt;Create two arrays. Use the _character_ and _numeric_ variable list shorthand.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 19 Jun 2017 14:25:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-put-to-change-data-format-into-charater/m-p/368343#M87839</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-06-19T14:25:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to use 'put' to change data format into charater?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-put-to-change-data-format-into-charater/m-p/368348#M87841</link>
      <description>&lt;P&gt;Depending on what you actually attempt and are going to use the data for&amp;nbsp;be aware that you may need to consider leading blanks in the resulting variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 19 Jun 2017 14:34:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-put-to-change-data-format-into-charater/m-p/368348#M87841</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-06-19T14:34:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to use 'put' to change data format into charater?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-put-to-change-data-format-into-charater/m-p/368356#M87844</link>
      <description>&lt;P&gt;Read the instructions at the bottom of the post a question. &amp;nbsp;Post example test data in the form of a datastep, and what you want the output to look like. &amp;nbsp;From the little you post I would guess by date variables you have numeric date variables. &amp;nbsp;Is there a simple way of identifying these from the name? &amp;nbsp;If so you can use&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;'s suggestion and simply:&lt;/P&gt;
&lt;PRE&gt;data want;
  set have;
  array nums _numeric_;
  array char_res{150} $100;
  do i =1 to 150;
    call vname(nums{i},name);
    if substr(name,1,4)=date then char_res{i}=put(nums{i},date9.);
    else put(nums{i},best.);
  end;
run;&lt;/PRE&gt;</description>
      <pubDate>Mon, 19 Jun 2017 15:10:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-put-to-change-data-format-into-charater/m-p/368356#M87844</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-06-19T15:10:34Z</dc:date>
    </item>
    <item>
      <title>Re: How to use 'put' to change data format into charater?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-put-to-change-data-format-into-charater/m-p/368358#M87846</link>
      <description>&lt;P&gt;Where is the list of variable names to convert coming from? Do you have them in a dataset? Or as a space delimited list of names in a macro variable?&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;Are there going to be any numeric variables left in the data set? &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It might just be easier to write the data to a text file and read it back in using the same variable names, but as character varaibles.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc contents data=have noprint out=contents; run;
proc sql noprint ;
  select varnum,name 
    into :varlist,:varlist separated by ' ' 
    from contents
    order by 1
  ;
quit;
filename rawdata temp;
data _null_;
  set have ;
  file rawdata dsd lrecl=1000000 ;
  put &amp;amp;varlist ;
run;
data want ;
  length &amp;amp;varlist $20 ;
  infile rawdata dsd truncover lrecl=1000000;
  input &amp;amp;varlist ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 19 Jun 2017 15:24:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-put-to-change-data-format-into-charater/m-p/368358#M87846</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-06-19T15:24:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to use 'put' to change data format into charater?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-put-to-change-data-format-into-charater/m-p/368727#M87956</link>
      <description>&lt;PRE&gt;Make a macro.    


data class;
 set sashelp.class;
run;

data _null_;
 set sashelp.vcolumn(
keep=libname memname type name
where=(libname='WORK' and memname='CLASS' and type='num')) end=last;
if _n_=1 then call execute('data want; set class;');
call execute(catt('char_',name,'=vvalue(',name,');'));
if last then call execute('run;');
run;      &lt;/PRE&gt;</description>
      <pubDate>Tue, 20 Jun 2017 14:06:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-put-to-change-data-format-into-charater/m-p/368727#M87956</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-06-20T14:06:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to use 'put' to change data format into charater?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-put-to-change-data-format-into-charater/m-p/368933#M87994</link>
      <description>&lt;P&gt;Thanks for the thoughtful explaination.&lt;/P&gt;</description>
      <pubDate>Tue, 20 Jun 2017 20:27:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-put-to-change-data-format-into-charater/m-p/368933#M87994</guid>
      <dc:creator>ybz12003</dc:creator>
      <dc:date>2017-06-20T20:27:32Z</dc:date>
    </item>
  </channel>
</rss>

