<?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: Import number turn to text in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Import-number-turn-to-text/m-p/534619#M146723</link>
    <description>&lt;P&gt;That is not a good format for a guessing procedure like PROC IMPORT.&amp;nbsp; Having date in metadata (variable names) is not a good idea in general.&amp;nbsp; Since your file is just a text file you can instead just read it with a data step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want ;
 length id $40 date 8 value 8 ;
 infile "&amp;amp;path/sample.csv" dsd truncover ;
 if _n_=1 then do ;
   array dates (100) _temporary_;
   input id @ ;
   do ncol=1 by 1 until(date=.);
     input date :??mmddyy. @ ;
     dates(ncol)=date ;
   end;
   ncol=ncol-1;
   retain ncol;
   input ;
 end;
 input id @;
 do col=1 to ncol;
   input value ?? @;
   date=dates(col);
   output;
 end;
 drop col ncol;
 format date yymmdd10.;
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;Note that your file also has text string ' -&amp;nbsp; ' for some of the values.&amp;nbsp; I have told the data step to just make those missing.&amp;nbsp; You could create a custom INFORMAT that would set those to a special missing instead.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could recreate your original report from that data structure by using PROC REPORT.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc report data=want;
  where date between '01DEC2018'd and '05dec2018'd ;
  columns id value,date ;
  define id / group ;
  define date / across ' ';
  define value / ' ';
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="image.png" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/27063i53DE035C82CF6B46/image-size/large?v=v2&amp;amp;px=999" role="button" title="image.png" alt="image.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 11 Feb 2019 21:14:33 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2019-02-11T21:14:33Z</dc:date>
    <item>
      <title>Import number turn to text</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-number-turn-to-text/m-p/534604#M146714</link>
      <description>&lt;P&gt;Hi Everyone,&lt;/P&gt;
&lt;P&gt;I run the proc import below to import my file (attached).&lt;/P&gt;
&lt;P&gt;However, some column of number turn to character.&lt;/P&gt;
&lt;P&gt;Can you help me to change all variables starting with _&amp;nbsp; into numeric?&lt;/P&gt;
&lt;P&gt;Thank you for your help.&lt;/P&gt;
&lt;P&gt;HHCFX&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Each month, I need to import similar file and I don't know how many column there are. Thus, using data step might not be good idea for me.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;	%put &amp;amp;=sysvlong ;
	options validvarname=v7 ;
		proc import datafile="C:\Users\sample.CSV"
	out=client dbms=CSV replace; 
		getnames=yes; 
	guessingrows=100;
	run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 11 Feb 2019 20:28:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-number-turn-to-text/m-p/534604#M146714</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2019-02-11T20:28:14Z</dc:date>
    </item>
    <item>
      <title>Re: Import number turn to text</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-number-turn-to-text/m-p/534609#M146715</link>
      <description>Will the data always have this form, ID, date start to date end + grand total?</description>
      <pubDate>Mon, 11 Feb 2019 20:40:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-number-turn-to-text/m-p/534609#M146715</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-02-11T20:40:30Z</dc:date>
    </item>
    <item>
      <title>Re: Import number turn to text</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-number-turn-to-text/m-p/534610#M146716</link>
      <description>&lt;P&gt;Yes, the actual data always has number column starts in column 4.&lt;/P&gt;
&lt;P&gt;In the sample uploaded, I delete 2 first column.&lt;/P&gt;
&lt;P&gt;and it also ended with grand total.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 11 Feb 2019 20:45:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-number-turn-to-text/m-p/534610#M146716</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2019-02-11T20:45:59Z</dc:date>
    </item>
    <item>
      <title>Re: Import number turn to text</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-number-turn-to-text/m-p/534612#M146718</link>
      <description>Is there a way to determine how many dates you should have in the file, based on current date or date of report?</description>
      <pubDate>Mon, 11 Feb 2019 20:55:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-number-turn-to-text/m-p/534612#M146718</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-02-11T20:55:15Z</dc:date>
    </item>
    <item>
      <title>Re: Import number turn to text</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-number-turn-to-text/m-p/534615#M146721</link>
      <description>&lt;P&gt;The report will contain every days in a calendar month.&lt;/P&gt;
&lt;P&gt;So to a certain extend, the answer is Yes. but there might be a need of an If-then for number of day in month.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 11 Feb 2019 21:08:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-number-turn-to-text/m-p/534615#M146721</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2019-02-11T21:08:25Z</dc:date>
    </item>
    <item>
      <title>Re: Import number turn to text</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-number-turn-to-text/m-p/534617#M146722</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/49486"&gt;@hhchenfx&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi Everyone,&lt;/P&gt;
&lt;P&gt;I run the proc import below to import my file (attached).&lt;/P&gt;
&lt;P&gt;However, some column of number turn to character.&lt;/P&gt;
&lt;P&gt;Can you help me to change all variables starting with _&amp;nbsp; into numeric?&lt;/P&gt;
&lt;P&gt;Thank you for your help.&lt;/P&gt;
&lt;P&gt;HHCFX&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Each month, I need to import similar file and I don't know how many column there are. Thus, using data step might not be good idea for me.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;	%put &amp;amp;=sysvlong ;
	options validvarname=v7 ;
		proc import datafile="C:\Users\sample.CSV"
	out=client dbms=CSV replace; 
		getnames=yes; 
	guessingrows=100;
	run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;The problem is that your data contains values that are not numeric&lt;/P&gt;
&lt;P&gt;Example from your file the first 5 rows:&lt;/P&gt;
&lt;PRE&gt;X1B_X1SF_X1TI_DWX1,,,8,8,8,8,8,,,8,8,8.5,8,7.5,,,8,8,8,8,8,,,8, -   ,8,8,,,,8,152
X1B_X1SF_X1TI_PJM_II,,,6.5,6,7.5,8,8,,,8,9,9.5,6,4.5,,,8.5,6,4,4,6.5,,,8,,,4,6,,,7,127
X1B_X1SF_X1TI_PJM_II,,,1.5,5,2,1,,,,,,,4,3,,,,3,6,7,2,,,,,,,4.5,,,1,40
X1B_X1SF_X1TI_SX1_II,,,8,8,8,8,8,,,6,9,9,8,6.5,,,8,8,8,8,8,,,8,,8,8,8,,,8,158.5
X1B_X1SF_X1TI_DWX1,,,,,,,,,,,,,,,,,,,,,,,,8, -   , -   , -   , -   ,,,8,16
&lt;/PRE&gt;
&lt;P&gt;Those fields that contain dashes are character not numeric. You have more examples further down in your file. Any column that has a dash in the first 100 rows (your guessing rows) will be set to character type.&lt;/P&gt;
&lt;P&gt;Time to write a data step to read things correctly, whatever "correctly" may mean in the presence of a dash surrounded by several spaces.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Not terrible fond of making variable names alike '12/1/2018'n either. That way your variable name contains actual data in the name.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 11 Feb 2019 21:14:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-number-turn-to-text/m-p/534617#M146722</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-02-11T21:14:01Z</dc:date>
    </item>
    <item>
      <title>Re: Import number turn to text</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-number-turn-to-text/m-p/534619#M146723</link>
      <description>&lt;P&gt;That is not a good format for a guessing procedure like PROC IMPORT.&amp;nbsp; Having date in metadata (variable names) is not a good idea in general.&amp;nbsp; Since your file is just a text file you can instead just read it with a data step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want ;
 length id $40 date 8 value 8 ;
 infile "&amp;amp;path/sample.csv" dsd truncover ;
 if _n_=1 then do ;
   array dates (100) _temporary_;
   input id @ ;
   do ncol=1 by 1 until(date=.);
     input date :??mmddyy. @ ;
     dates(ncol)=date ;
   end;
   ncol=ncol-1;
   retain ncol;
   input ;
 end;
 input id @;
 do col=1 to ncol;
   input value ?? @;
   date=dates(col);
   output;
 end;
 drop col ncol;
 format date yymmdd10.;
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;Note that your file also has text string ' -&amp;nbsp; ' for some of the values.&amp;nbsp; I have told the data step to just make those missing.&amp;nbsp; You could create a custom INFORMAT that would set those to a special missing instead.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could recreate your original report from that data structure by using PROC REPORT.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc report data=want;
  where date between '01DEC2018'd and '05dec2018'd ;
  columns id value,date ;
  define id / group ;
  define date / across ' ';
  define value / ' ';
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="image.png" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/27063i53DE035C82CF6B46/image-size/large?v=v2&amp;amp;px=999" role="button" title="image.png" alt="image.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 11 Feb 2019 21:14:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-number-turn-to-text/m-p/534619#M146723</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-02-11T21:14:33Z</dc:date>
    </item>
    <item>
      <title>Re: Import number turn to text</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-number-turn-to-text/m-p/534626#M146725</link>
      <description>&lt;P&gt;I see.&lt;/P&gt;
&lt;P&gt;I can replace all these "-" with blank in Excel in the new file enclosed&lt;/P&gt;
&lt;P&gt;can it help to simplify the problem?&lt;/P&gt;</description>
      <pubDate>Mon, 11 Feb 2019 21:32:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-number-turn-to-text/m-p/534626#M146725</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2019-02-11T21:32:37Z</dc:date>
    </item>
    <item>
      <title>Re: Import number turn to text</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-number-turn-to-text/m-p/534639#M146732</link>
      <description>&lt;P&gt;I really appreciate your help!&lt;/P&gt;
&lt;P&gt;HHCFX&lt;/P&gt;</description>
      <pubDate>Mon, 11 Feb 2019 22:15:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-number-turn-to-text/m-p/534639#M146732</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2019-02-11T22:15:14Z</dc:date>
    </item>
    <item>
      <title>Re: Import number turn to text</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-number-turn-to-text/m-p/534888#M146831</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/49486"&gt;@hhchenfx&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I see.&lt;/P&gt;
&lt;P&gt;I can replace all these "-" with blank in Excel in the new file enclosed&lt;/P&gt;
&lt;P&gt;can it help to simplify the problem?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;It is likely actually easier to apply rules in SAS as &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;shows&amp;nbsp;&amp;nbsp;then to add a manual step in Excel&amp;nbsp;that could cause other issues.&lt;/P&gt;</description>
      <pubDate>Tue, 12 Feb 2019 15:49:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-number-turn-to-text/m-p/534888#M146831</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-02-12T15:49:34Z</dc:date>
    </item>
    <item>
      <title>Re: Import number turn to text</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-number-turn-to-text/m-p/534889#M146832</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/49486"&gt;@hhchenfx&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I see.&lt;/P&gt;
&lt;P&gt;I can replace all these "-" with blank in Excel in the new file enclosed&lt;/P&gt;
&lt;P&gt;can it help to simplify the problem?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Opening a CSV file in Excel can cause a lot of problems.&amp;nbsp; If you are not careful Excel will transform some of the value.&amp;nbsp; For example it might convert character variables with hyphens in them into dates.&lt;/P&gt;</description>
      <pubDate>Tue, 12 Feb 2019 15:51:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-number-turn-to-text/m-p/534889#M146832</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-02-12T15:51:24Z</dc:date>
    </item>
  </channel>
</rss>

