<?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: Forcing a numeric type on a predominately character column when importing from excel in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Forcing-a-numeric-type-on-a-predominately-character-column-when/m-p/462140#M117601</link>
    <description>&lt;P&gt;After importing the file, just create a new numeric variable to replace AGEC.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Verdana" size="3"&gt;&lt;STRONG&gt;DATA&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Verdana" size="3"&gt; want; &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Verdana" size="3"&gt;SET&lt;/FONT&gt;&lt;FONT face="Verdana" size="3"&gt; have;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Verdana" size="3"&gt;format&lt;/FONT&gt;&lt;FONT face="Verdana" size="3"&gt;&amp;nbsp;AGENUMERIC &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Verdana" size="3"&gt;2.&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Verdana" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;AGENUMERIC=AGEC;&lt;/P&gt;
&lt;P&gt;DROP AGEC;&lt;/P&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Verdana" size="3"&gt;run&lt;/FONT&gt;&lt;FONT face="Verdana" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 14 May 2018 17:22:38 GMT</pubDate>
    <dc:creator>nketata</dc:creator>
    <dc:date>2018-05-14T17:22:38Z</dc:date>
    <item>
      <title>Forcing a numeric type on a predominately character column when importing from excel</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Forcing-a-numeric-type-on-a-predominately-character-column-when/m-p/327754#M73131</link>
      <description>&lt;P&gt;Forcing a numeric type on a predominately character column when importing from excel&lt;/P&gt;&lt;P&gt;Interesting excel issue on SAS-L&lt;/P&gt;&lt;P&gt;source&lt;BR /&gt;&lt;A href="https://listserv.uga.edu/cgi-bin/wa?A2=SAS-L;440cf102.1701d" target="_blank"&gt;https://listserv.uga.edu/cgi-bin/wa?A2=SAS-L;440cf102.1701d&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Passthru is the best solution because you can fix things on the excel side before&lt;BR /&gt;SAS transforms the data. MS SQL on MS excell.&lt;/P&gt;&lt;P&gt;A dumb example.&lt;/P&gt;&lt;P&gt;Cannot be absolutely sure of the results below because I have Access to PC Files&lt;/P&gt;&lt;P&gt;With Access to PC-Files&lt;/P&gt;&lt;P&gt;1. Use DBSASTYPE option&lt;BR /&gt;2. Use mix option (works with and without Access to PC Files&lt;BR /&gt;3. Use passthru to excel&lt;/P&gt;&lt;P&gt;* Without Access to PC files&lt;/P&gt;&lt;P&gt;4. SAS Use mix option and proc import as character then change in SAS (do not need Access to PC-Files?)&lt;BR /&gt;5. SAS Use addtics VBA macro and proc import to force all columns to be character (if predominately numeric change later)&lt;/P&gt;&lt;P&gt;Without SAS and no limit on number of obs in SAS dataset&lt;/P&gt;&lt;P&gt;6. WPS/R Forces a numeric type so all character values are converted to missing&lt;/P&gt;&lt;P&gt;HAVE excel workbook d:/xls/class.xlsx and sheet=class&lt;BR /&gt;========================================================&lt;/P&gt;&lt;P&gt;Up to 40 obs from d:/xls/class.xlsx total obs=19&lt;/P&gt;&lt;P&gt;AGEC NAME SEX AGE HEIGHT WEIGHT&lt;/P&gt;&lt;P&gt;AA Alfred M 14 69 112.5&lt;BR /&gt;AA Alice F 13 56.5 84&lt;BR /&gt;AA Barbara F 13 65.3 98&lt;BR /&gt;AA Carol F 14 62.8 102.5&lt;BR /&gt;AA Henry M 14 63.5 102.5&lt;BR /&gt;AA James M 12 57.3 83&lt;BR /&gt;AA Jane F 12 59.8 84.5&lt;BR /&gt;AA Janet F 15 62.5 112.5&lt;BR /&gt;AA Jeffrey M 13 62.5 84&lt;BR /&gt;AA John M 12 59 99.5&lt;BR /&gt;AA Joyce F 11 51.3 50.5&lt;BR /&gt;AA Judy F 14 64.3 90&lt;BR /&gt;AA Louise F 12 56.3 77&lt;BR /&gt;AA Mary F 15 66.5 112&lt;BR /&gt;AA Philip M 16 72 150&lt;BR /&gt;AA Robert M 12 64.8 128&lt;BR /&gt;AA Ronald M 15 67 133&lt;BR /&gt;AA Thomas M 11 57.5 85&lt;BR /&gt;99 William M 15 66.5 112&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;WANT SAS DATASET WORK.WANTWPS&lt;BR /&gt;==============================&lt;/P&gt;&lt;P&gt;Up to 40 obs from wantwps total obs=19&lt;/P&gt;&lt;P&gt;AGEC NAME SEX AGE HEIGHT WEIGHT&lt;/P&gt;&lt;P&gt;. Alfred M 14 69 112.5&lt;BR /&gt;. Alice F 13 56.5 84&lt;BR /&gt;. Barbara F 13 65.3 98&lt;BR /&gt;. Carol F 14 62.8 102.5&lt;BR /&gt;. Henry M 14 63.5 102.5&lt;BR /&gt;. James M 12 57.3 83&lt;BR /&gt;. Jane F 12 59.8 84.5&lt;BR /&gt;. Janet F 15 62.5 112.5&lt;BR /&gt;. Jeffrey M 13 62.5 84&lt;BR /&gt;. John M 12 59 99.5&lt;BR /&gt;. Joyce F 11 51.3 50.5&lt;BR /&gt;. Judy F 14 64.3 90&lt;BR /&gt;. Louise F 12 56.3 77&lt;BR /&gt;. Mary F 15 66.5 112&lt;BR /&gt;. Philip M 16 72 150&lt;BR /&gt;. Robert M 12 64.8 128&lt;BR /&gt;. Ronald M 15 67 133&lt;BR /&gt;. Thomas M 11 57.5 85&lt;BR /&gt;99 William M 15 66.5 112&lt;/P&gt;&lt;P&gt;WORKING CODE&lt;BR /&gt;=============&lt;/P&gt;&lt;P&gt;With Access to PC-Files&lt;/P&gt;&lt;P&gt;1. Use DBSASTYPE option&lt;BR /&gt;set xel.class(dbsastype=(agec='numeric'));&lt;/P&gt;&lt;P&gt;2. Use mix option (works with and without Access to PC Files&lt;BR /&gt;Comes in as character so you have to change in SAS&lt;/P&gt;&lt;P&gt;3. Use passthru to excel&lt;/P&gt;&lt;P&gt;* Without Access to PC files&lt;/P&gt;&lt;P&gt;4. SAS Use mix option and proc import as character then change in SAS (do not need Access to PC-Files?)&lt;BR /&gt;5. SAS Use addtics VBA macro and proc import to force all columns to be character (if predominately numeric change later)&lt;/P&gt;&lt;P&gt;Without SAS and no limit on number of obs in SAS dataset&lt;/P&gt;&lt;P&gt;6. WPS/R Forces a numeric type so all character values are converted to missing&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;* _ _ _&lt;BR /&gt;__| | |__ ___ __ _ ___| |_ _ _ _ __ ___&lt;BR /&gt;/ _` | '_ \/ __|/ _` / __| __| | | | '_ \ / _ \&lt;BR /&gt;| (_| | |_) \__ \ (_| \__ \ |_| |_| | |_) | __/&lt;BR /&gt;\__,_|_.__/|___/\__,_|___/\__|\__, | .__/ \___|&lt;BR /&gt;; |___/|_|&lt;/P&gt;&lt;P&gt;1. Use DBSASTYPE option&lt;/P&gt;&lt;P&gt;%utlfkil(d:\xls\class.xlsx);&lt;BR /&gt;libname xel "d:\xls\class.xlsx";&lt;/P&gt;&lt;P&gt;data xel.class;&lt;BR /&gt;retain agec;&lt;BR /&gt;set sashelp.class;&lt;BR /&gt;agec='AA';&lt;BR /&gt;if _n_=19 then agec='99';&lt;BR /&gt;run;quit;&lt;/P&gt;&lt;P&gt;;run;quit;&lt;/P&gt;&lt;P&gt;data class;&lt;BR /&gt;set xel.class(dbsastype=(agec='numeric'));&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;libname xel clear;&lt;/P&gt;&lt;P&gt;14 libname xel "d:/xls/class.xlsx";&lt;BR /&gt;NOTE: Libref XEL was successfully assigned as follows:&lt;BR /&gt;Engine: EXCEL&lt;BR /&gt;Physical Name: d:/xls/class.xlsx&lt;BR /&gt;15 data xel.class;&lt;BR /&gt;16 set sashelp.class;&lt;BR /&gt;17 ;run;&lt;/P&gt;&lt;P&gt;NOTE: There were 19 observations read from the data set SASHELP.CLASS.&lt;BR /&gt;NOTE: The data set XEL.class has 19 observations and 5 variables.&lt;BR /&gt;NOTE: DATA statement used (Total process time):&lt;BR /&gt;real time 0.02 seconds&lt;BR /&gt;cpu time 0.00 seconds&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;17 ! quit;&lt;BR /&gt;18 data class;&lt;BR /&gt;19 set xel.class(dbsastype=(age='numeric'));&lt;BR /&gt;20 run;&lt;/P&gt;&lt;P&gt;NOTE: There were 19 observations read from the data set XEL.class.&lt;BR /&gt;NOTE: The data set WORK.CLASS has 19 observations and 5 variables.&lt;BR /&gt;NOTE: DATA statement used (Total process time):&lt;BR /&gt;real time 0.05 seconds&lt;BR /&gt;cpu time 0.03 seconds&lt;/P&gt;&lt;P&gt;_ _&lt;BR /&gt;_ __ ___ (_)_ _____ __| |&lt;BR /&gt;| '_ ` _ \| \ \/ / _ \/ _` |&lt;BR /&gt;| | | | | | |&amp;gt; &amp;lt; __/ (_| |&lt;BR /&gt;|_| |_| |_|_/_/\_\___|\__,_|&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;PROC IMPORT OUT= mydata&lt;BR /&gt;DATAFILE= "d:/xls/class.xlsx"&lt;BR /&gt;DBMS=EXCEL REPLACE;&lt;BR /&gt;SHEET="'CLASS'";&lt;BR /&gt;GETNAMES=YES;&lt;BR /&gt;MIXED=yes;&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;_____ _&lt;BR /&gt;_ __ __ _ ___ __|_ _| |__ _ __ _ _&lt;BR /&gt;| '_ \ / _` / __/ __|| | | '_ \| '__| | | |&lt;BR /&gt;| |_) | (_| \__ \__ \| | | | | | | | |_| |&lt;BR /&gt;| .__/ \__,_|___/___/|_| |_| |_|_| \__,_|&lt;BR /&gt;|_|&lt;/P&gt;&lt;P&gt;proc sql dquote=ansi;&lt;BR /&gt;connect to excel (Path="d:\xls\class.xlsx" mixed=yes);&lt;BR /&gt;create&lt;BR /&gt;table classsql as&lt;BR /&gt;select * from connection to Excel&lt;BR /&gt;(&lt;BR /&gt;Select&lt;BR /&gt;*&lt;BR /&gt;,iif(isnumeric(agec),agec,'.') as agecfix&lt;BR /&gt;from&lt;BR /&gt;class&lt;BR /&gt;);&lt;BR /&gt;disconnect from Excel;&lt;BR /&gt;Quit;&lt;/P&gt;&lt;P&gt;%utl_optlen(inp=classsql, out=classsql);&lt;/P&gt;&lt;P&gt;Up to 40 obs from classsql total obs=19&lt;/P&gt;&lt;P&gt;Obs AGECFIX AGEC NAME SEX AGE HEIGHT WEIGHT&lt;/P&gt;&lt;P&gt;1 . AA Alfred M 14 69 112.5&lt;BR /&gt;2 . AA Alice F 13 56.5 84&lt;BR /&gt;3 . AA Barbara F 13 65.3 98&lt;BR /&gt;4 . AA Carol F 14 62.8 102.5&lt;BR /&gt;5 . AA Henry M 14 63.5 102.5&lt;BR /&gt;6 . AA James M 12 57.3 83&lt;BR /&gt;7 . AA Jane F 12 59.8 84.5&lt;BR /&gt;8 . AA Janet F 15 62.5 112.5&lt;BR /&gt;9 . AA Jeffrey M 13 62.5 84&lt;BR /&gt;10 . AA John M 12 59 99.5&lt;BR /&gt;11 . AA Joyce F 11 51.3 50.5&lt;BR /&gt;12 . AA Judy F 14 64.3 90&lt;BR /&gt;13 . AA Louise F 12 56.3 77&lt;BR /&gt;14 . AA Mary F 15 66.5 112&lt;BR /&gt;15 . AA Philip M 16 72 150&lt;BR /&gt;16 . AA Robert M 12 64.8 128&lt;BR /&gt;17 . AA Ronald M 15 67 133&lt;BR /&gt;18 . AA Thomas M 11 57.5 85&lt;BR /&gt;19 99 99 William M 15 66.5 112&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;_ _ _____ _ _&lt;BR /&gt;__ _ __| | __| |_ _(_) ___| | _____&lt;BR /&gt;/ _` |/ _` |/ _` | | | | |/ __| |/ / __|&lt;BR /&gt;| (_| | (_| | (_| | | | | | (__| &amp;lt;\__ \&lt;BR /&gt;\__,_|\__,_|\__,_| |_| |_|\___|_|\_\___/&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;/* T000225 CONVERTING ALL EXCEL CELLS TO CHARACTER */&lt;BR /&gt;Latest VBA macros Addticks - forces all excel cells to be character&lt;BR /&gt;before importing excel sheets to SAS this macro should be used&lt;/P&gt;&lt;P&gt;/* this will stop when cell has TIUQ which is quit backwards */&lt;BR /&gt;/* this is probably the best macro */&lt;BR /&gt;Sub AddTicks()&lt;BR /&gt;Dim LastPlace, Z As Variant, X As Variant&lt;BR /&gt;LastPlace = ActiveCell.SpecialCells(xlLastCell).Address&lt;BR /&gt;ActiveSheet.Range(Cells(1, 1), LastPlace).Select&lt;BR /&gt;Z = Selection.Address 'Get the address&lt;BR /&gt;For Each X In ActiveSheet.Range(Z) 'Do while&lt;BR /&gt;If Len(X) &amp;gt; 0 Then 'Find cells with something&lt;BR /&gt;X.FormulaR1C1 = Chr(39) &amp;amp; Mid(X, 1, Len(X)) '39 is code for tick&lt;BR /&gt;Else&lt;BR /&gt;X.FormulaR1C1 = "" 'If empty do not put tick&lt;BR /&gt;End If&lt;BR /&gt;If X = "TIUQ" Then&lt;BR /&gt;Exit Sub&lt;BR /&gt;End If&lt;BR /&gt;Next&lt;BR /&gt;End Sub&lt;/P&gt;&lt;P&gt;/* T000226 REMOVES TICKS FROM EXCEL CELLS */&lt;BR /&gt;Sub RemoveTicks()&lt;BR /&gt;For Each currentcell In Selection&lt;BR /&gt;If currentcell.HasFormula = False Then&lt;BR /&gt;'Verifies that procedure does not change the&lt;BR /&gt;'cell with the active formula so that it contains&lt;BR /&gt;'only the value.&lt;BR /&gt;currentcell.Formula = currentcell.Value&lt;BR /&gt;End If&lt;BR /&gt;Next&lt;BR /&gt;End Sub&lt;/P&gt;&lt;P&gt;__ ______ ____ ____&lt;BR /&gt;\ \ / / _ \/ ___| | _ \&lt;BR /&gt;\ \ /\ / /| |_) \___ \ _____| |_) |&lt;BR /&gt;\ V V / | __/ ___) |_____| _ &amp;lt;&lt;BR /&gt;\_/\_/ |_| |____/ |_| \_\&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Note you can do this with IML interface to R&lt;BR /&gt;%utl_submit_wps64('&lt;BR /&gt;options set=R_HOME "C:/Program Files/R/R-3.3.2";&lt;BR /&gt;libname wrk "%sysfunc(pathname(work))";&lt;BR /&gt;proc r;&lt;BR /&gt;submit;&lt;BR /&gt;source("C:/Program Files/R/R-3.3.2/etc/Rprofile.site", echo=T);&lt;BR /&gt;library(XLConnect);&lt;BR /&gt;wb &amp;lt;- loadWorkbook("d:/xls/class.xlsx");&lt;BR /&gt;agen&amp;lt;-readWorksheet(wb, "class", keep="AGEC", colTypes="numeric", forceConversion=TRUE);&lt;BR /&gt;shet&amp;lt;-readWorksheet(wb, "class", drop="AGEC");&lt;BR /&gt;df&amp;lt;-cbind(agen,shet);&lt;BR /&gt;class(df);&lt;BR /&gt;saveWorkbook(wb)&lt;BR /&gt;endsubmit;&lt;BR /&gt;import r=df data=wrk.wantwps;&lt;BR /&gt;run;quit;&lt;BR /&gt;');&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 26 Jan 2017 16:09:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Forcing-a-numeric-type-on-a-predominately-character-column-when/m-p/327754#M73131</guid>
      <dc:creator>rogerjdeangelis</dc:creator>
      <dc:date>2017-01-26T16:09:17Z</dc:date>
    </item>
    <item>
      <title>Re: Forcing a numeric type on a predominately character column when importing from excel</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Forcing-a-numeric-type-on-a-predominately-character-column-when/m-p/462140#M117601</link>
      <description>&lt;P&gt;After importing the file, just create a new numeric variable to replace AGEC.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Verdana" size="3"&gt;&lt;STRONG&gt;DATA&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Verdana" size="3"&gt; want; &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Verdana" size="3"&gt;SET&lt;/FONT&gt;&lt;FONT face="Verdana" size="3"&gt; have;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Verdana" size="3"&gt;format&lt;/FONT&gt;&lt;FONT face="Verdana" size="3"&gt;&amp;nbsp;AGENUMERIC &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Verdana" size="3"&gt;2.&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Verdana" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;AGENUMERIC=AGEC;&lt;/P&gt;
&lt;P&gt;DROP AGEC;&lt;/P&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Verdana" size="3"&gt;run&lt;/FONT&gt;&lt;FONT face="Verdana" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 14 May 2018 17:22:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Forcing-a-numeric-type-on-a-predominately-character-column-when/m-p/462140#M117601</guid>
      <dc:creator>nketata</dc:creator>
      <dc:date>2018-05-14T17:22:38Z</dc:date>
    </item>
  </channel>
</rss>

