<?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: Creating a case and assigning values to appropriate columns based on the data type in SAS in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-case-and-assigning-values-to-appropriate-columns/m-p/362107#M85514</link>
    <description>&lt;P&gt;What's %datatyp?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Why not use VTYPE in a data step, it won't work in SQL?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, rather than this, use SASHELP.VCOLUMN which holds the metadata for your tables so you can see which tables you need to change.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 27 May 2017 00:14:22 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2017-05-27T00:14:22Z</dc:date>
    <item>
      <title>Creating a case and assigning values to appropriate columns based on the data type in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-case-and-assigning-values-to-appropriate-columns/m-p/362104#M85512</link>
      <description>&lt;P&gt;I am importing excel spreadsheets and each sheet is in the same layout.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a column called &lt;CODE&gt;New_Value&lt;/CODE&gt; that has a value of unknown data type since it is being imported from one column in excel sheet (therefore, if all values in that column are numeric, then SAS will create this column as numeric type, but if that column has mixed data, SAS will assign the character data type).&lt;/P&gt;&lt;P&gt;This is how I import and create multiple sets (depending on how many files are in the folder):&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;proc sql;
    CREATE TABLE tmp&amp;amp;cnt. AS SELECT DISTINCT * FROM xl.Sheet2;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Then, I need to figure out if the value is character type or numeric type, because I need to separate them into different columns in the database. My problem is that I am unable to figure out the way to distinguish value types. This is what I have tried, but it always gives me the type of CHAR, although in some test scenarios the type is actually a NUMBER&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;SELECT
CASE 
 WHEN ("%DataTyp(New_Value)" = 'NUMERIC') THEN 0
 WHEN ("%DataTyp(New_Value)" = 'CHAR') THEN 1
 ELSE 2
END as is_char, 
"%DataTyp(New_Value)" as value_type
FROM tmp&amp;amp;cnt.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Basically, the final goal is to&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Check if the &lt;STRONG&gt;New_Value&lt;/STRONG&gt; is a Character or a Numeric type&lt;/LI&gt;&lt;LI&gt;If the &lt;STRONG&gt;New_Value&lt;/STRONG&gt; is a number, store it as the &lt;CODE&gt;value_numerical&lt;/CODE&gt; field&lt;/LI&gt;&lt;LI&gt;If the &lt;STRONG&gt;New_Value&lt;/STRONG&gt; is a character but contains a numeric value, convert it to numeric and store it as the &lt;CODE&gt;value_numerical&lt;/CODE&gt; field&lt;/LI&gt;&lt;LI&gt;If the &lt;STRONG&gt;New_Value&lt;/STRONG&gt; is a char, store it as the &lt;CODE&gt;value_text&lt;/CODE&gt; field&lt;/LI&gt;&lt;/OL&gt;</description>
      <pubDate>Fri, 26 May 2017 23:38:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-case-and-assigning-values-to-appropriate-columns/m-p/362104#M85512</guid>
      <dc:creator>rayzak</dc:creator>
      <dc:date>2017-05-26T23:38:59Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a case and assigning values to appropriate columns based on the data type in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-case-and-assigning-values-to-appropriate-columns/m-p/362107#M85514</link>
      <description>&lt;P&gt;What's %datatyp?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Why not use VTYPE in a data step, it won't work in SQL?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, rather than this, use SASHELP.VCOLUMN which holds the metadata for your tables so you can see which tables you need to change.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 27 May 2017 00:14:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-case-and-assigning-values-to-appropriate-columns/m-p/362107#M85514</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-05-27T00:14:22Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a case and assigning values to appropriate columns based on the data type in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-case-and-assigning-values-to-appropriate-columns/m-p/362158#M85522</link>
      <description>&lt;P&gt;You should distinguish between 3 options:&lt;/P&gt;
&lt;P&gt;1) the column is numeric only, then VTYPE is numeric&lt;/P&gt;
&lt;P&gt;2) the column is CHAR type, then you need test the variable&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; is it numeric - digits only - or alphanumeric.&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;You can do the test, either by:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;- &amp;nbsp;if not missing(input(var,best8.,??) ) then NUMERIC; else ALPHANUMERIC&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;- &amp;nbsp;if &amp;nbsp;var ne ' ' and translate(var,' ','0123456789') = ' ' then NUMERIC else ALPHANUMERIC&lt;/P&gt;</description>
      <pubDate>Sat, 27 May 2017 06:28:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-case-and-assigning-values-to-appropriate-columns/m-p/362158#M85522</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2017-05-27T06:28:07Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a case and assigning values to appropriate columns based on the data type in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-case-and-assigning-values-to-appropriate-columns/m-p/362770#M85733</link>
      <description>&lt;P&gt;Unforunately, there is no VTYPE in PROC SQL.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I came up with the following method:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;	CASE 
		WHEN NOT missing(input(cats(New_Value), best8.))
			THEN input(cats(New_Val), best8.)
		END AS value_numerical,
		
	CASE 
		WHEN missing(input(cats(New_Value), best8.))
			THEN cats(New_Val)
		END AS value_character&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am hoping it will satisfy my needs&lt;/P&gt;</description>
      <pubDate>Tue, 30 May 2017 15:55:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-case-and-assigning-values-to-appropriate-columns/m-p/362770#M85733</guid>
      <dc:creator>rayzak</dc:creator>
      <dc:date>2017-05-30T15:55:57Z</dc:date>
    </item>
  </channel>
</rss>

