<?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: SAS Formats when using OleDbConnection in Developers</title>
    <link>https://communities.sas.com/t5/Developers/SAS-Formats-when-using-OleDbConnection/m-p/688643#M968</link>
    <description>&lt;P&gt;Thanks Chris. I ultimately did something very similar. I will be pushing the whole solution to github at&amp;nbsp;&lt;A href="https://github.com/savian-net/ExportFromSasDataset" target="_blank"&gt;https://github.com/savian-net/ExportFromSasDataset&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is the pertinent snippet for posterity:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
        /// &amp;lt;summary&amp;gt;
        /// Gets a SAS dataset from the specified location but using the SAS formats for the results. Only supported
        /// Base SAS formats will be handled. If a user-defined format is encountered, the method will fail.
        /// &amp;lt;/summary&amp;gt;
        /// &amp;lt;param name="sasLibrary"&amp;gt;The physical location of the SAS library to read in the data &amp;lt;/param&amp;gt;
        /// &amp;lt;param name="sasDataSet"&amp;gt;The name of the SAS dataset to read&amp;lt;/param&amp;gt;
        /// &amp;lt;returns&amp;gt;.NET datatable. All values returned will be strings.&amp;lt;/returns&amp;gt;
        public static DataTable GetDataSet(string sasLibrary, string sasDataSet)
        {
            DataTable dt = new DataTable();
            try
            {
                ADODB.Recordset set = new ADODB.Recordset();
                ADODB.Connection conn = new ADODB.Connection();
                conn.Provider = "sas.LocalProvider.1";
                conn.Properties["Data Source"].Value = sasLibrary;
                conn.Open();
                set.ActiveConnection = conn;
                var connProps = conn.Properties.OfType&amp;lt;ADODB.Property&amp;gt;().Select(p =&amp;gt; new { p.Name, p.Value }).ToList();
                var recordSetProps = set.Properties.OfType&amp;lt;ADODB.Property&amp;gt;().Select(p =&amp;gt; new { p.Name, p.Value }).ToList();
                if (_options.Formatted)
                {
                    set.Properties["SAS Formats"].Value = "_ALL_";
                }
                set.Open(sasDataSet, Missing.Value, ADODB.CursorTypeEnum.adOpenForwardOnly, ADODB.LockTypeEnum.adLockReadOnly, (int)ADODB.CommandTypeEnum.adCmdTableDirect);
                OleDbDataAdapter da = new OleDbDataAdapter();
                da.Fill(dt, set);
                dt.TableName = sasDataSet.ToUpper();
                conn.Close();
                return dt;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 03 Oct 2020 01:15:40 GMT</pubDate>
    <dc:creator>AlanC</dc:creator>
    <dc:date>2020-10-03T01:15:40Z</dc:date>
    <item>
      <title>SAS Formats when using OleDbConnection</title>
      <link>https://communities.sas.com/t5/Developers/SAS-Formats-when-using-OleDbConnection/m-p/685288#M944</link>
      <description>&lt;P&gt;I have the following connection string:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  sas = new OleDbConnection($@"Provider=sas.LocalProvider.1; Data Source={_options.SasLibrary};");&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I then do the normal request of the table:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;                sas.Open();
                OleDbCommand sasCommand = sas.CreateCommand();
                sasCommand.CommandType = CommandType.TableDirect;
                sasCommand.CommandText = sasDataSet;
                var sasRead = sasCommand.ExecuteReader();
                var dt = new DataTable();
                dt.Load(sasRead);
                sas.Close();

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;How do I specify that the data should return formatted? We used to have "SAS Formats" = _ALL_ but that does not work (I have tried numerous variations). How can we pass the SAS Formats property to a .NET Core OleDb provider?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 20 Sep 2020 21:52:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Developers/SAS-Formats-when-using-OleDbConnection/m-p/685288#M944</guid>
      <dc:creator>AlanC</dc:creator>
      <dc:date>2020-09-20T21:52:03Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Formats when using OleDbConnection</title>
      <link>https://communities.sas.com/t5/Developers/SAS-Formats-when-using-OleDbConnection/m-p/687839#M962</link>
      <description>&lt;P&gt;In PowerShell, I've used this to set the Properties on a connection/recordset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;try {
    $objConnection.Open("Provider=SAS.LocalProvider;Data Source=`"$filePath`";")
    $objRecordset.ActiveConnection = $objConnection
    $objRecordset.Properties.Item("SAS Formats").Value = "_ALL_"

    # open the data set
    # IMPORTANT: passing in a "missing" value for the connection
    # because the connection is already on the RecordSet object
    $objRecordset.Open($filename, [Type]::Missing,
        $adOpenDynamic, `
            $adLockOptimistic, `
            $adCmdTableDirect) 
	   
    $objRecordset.MoveFirst()

    # read all of the records within the SAS data file
    do {
        # build up a new object with the field values
        $objectRecord = New-Object psobject
		
        for ($i = 0; $i -lt $objRecordset.Fields.Count; $i++) {
            # add static properties for each record
            $objectRecord | add-member noteproperty `
                -name $objRecordset.Fields.Item($i).Name `
                -value  $objRecordset.Fields.Item($i).Value;
			 
        }
        # emit the object as output from this script
        $objectRecord
		
        # move on to the next record
        $objRecordset.MoveNext()
    } 
    until ($objRecordset.EOF -eq $True)

    # close all of the connections
    $objRecordset.Close()
    $objConnection.Close()
}&lt;/PRE&gt;
&lt;P&gt;But I don't know how that translates to .NET Core and the approach you're using with the OleDbCommand.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 14:57:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Developers/SAS-Formats-when-using-OleDbConnection/m-p/687839#M962</guid>
      <dc:creator>ChrisHemedinger</dc:creator>
      <dc:date>2020-09-30T14:57:22Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Formats when using OleDbConnection</title>
      <link>https://communities.sas.com/t5/Developers/SAS-Formats-when-using-OleDbConnection/m-p/688643#M968</link>
      <description>&lt;P&gt;Thanks Chris. I ultimately did something very similar. I will be pushing the whole solution to github at&amp;nbsp;&lt;A href="https://github.com/savian-net/ExportFromSasDataset" target="_blank"&gt;https://github.com/savian-net/ExportFromSasDataset&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is the pertinent snippet for posterity:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
        /// &amp;lt;summary&amp;gt;
        /// Gets a SAS dataset from the specified location but using the SAS formats for the results. Only supported
        /// Base SAS formats will be handled. If a user-defined format is encountered, the method will fail.
        /// &amp;lt;/summary&amp;gt;
        /// &amp;lt;param name="sasLibrary"&amp;gt;The physical location of the SAS library to read in the data &amp;lt;/param&amp;gt;
        /// &amp;lt;param name="sasDataSet"&amp;gt;The name of the SAS dataset to read&amp;lt;/param&amp;gt;
        /// &amp;lt;returns&amp;gt;.NET datatable. All values returned will be strings.&amp;lt;/returns&amp;gt;
        public static DataTable GetDataSet(string sasLibrary, string sasDataSet)
        {
            DataTable dt = new DataTable();
            try
            {
                ADODB.Recordset set = new ADODB.Recordset();
                ADODB.Connection conn = new ADODB.Connection();
                conn.Provider = "sas.LocalProvider.1";
                conn.Properties["Data Source"].Value = sasLibrary;
                conn.Open();
                set.ActiveConnection = conn;
                var connProps = conn.Properties.OfType&amp;lt;ADODB.Property&amp;gt;().Select(p =&amp;gt; new { p.Name, p.Value }).ToList();
                var recordSetProps = set.Properties.OfType&amp;lt;ADODB.Property&amp;gt;().Select(p =&amp;gt; new { p.Name, p.Value }).ToList();
                if (_options.Formatted)
                {
                    set.Properties["SAS Formats"].Value = "_ALL_";
                }
                set.Open(sasDataSet, Missing.Value, ADODB.CursorTypeEnum.adOpenForwardOnly, ADODB.LockTypeEnum.adLockReadOnly, (int)ADODB.CommandTypeEnum.adCmdTableDirect);
                OleDbDataAdapter da = new OleDbDataAdapter();
                da.Fill(dt, set);
                dt.TableName = sasDataSet.ToUpper();
                conn.Close();
                return dt;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 03 Oct 2020 01:15:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Developers/SAS-Formats-when-using-OleDbConnection/m-p/688643#M968</guid>
      <dc:creator>AlanC</dc:creator>
      <dc:date>2020-10-03T01:15:40Z</dc:date>
    </item>
  </channel>
</rss>

