<?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 SAS macro for reading various datasets with different formats and field name in SAS Data Management</title>
    <link>https://communities.sas.com/t5/SAS-Data-Management/SAS-macro-for-reading-various-datasets-with-different-formats/m-p/305420#M8715</link>
    <description>&lt;P&gt;I want &amp;nbsp;a macro that allows to read sas dataset from a library 'athm'. I need a macro coz&amp;nbsp;I have about more than &amp;nbsp;50 sas datasets &amp;nbsp;&amp;amp;&lt;SPAN&gt;X._reportdata_allyears_&amp;amp;i &amp;nbsp;and create a &amp;nbsp;data table &amp;nbsp;with common fields and later do some summary statistics. To break down, I want to run for 2012 to 2016.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Problem: Some of the tables have different coulmn names( such as &amp;nbsp;Numerator , num ,N ,&amp;nbsp;Nu, nume ) to mean the same thing. For example AB_reportdata_allyears_2012 has &amp;nbsp;a field &amp;nbsp;Numerator &amp;nbsp;and AB&lt;SPAN&gt;_reportdata_allyears_2013 has Num &amp;nbsp;to mean the same thing.&amp;nbsp;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN&gt;In one&amp;nbsp;dataset, the column 'Year ' is character and in other dataset, the column 'Year' is numeric. I want to make&amp;nbsp;year to &amp;nbsp;a character value for all datasets.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried the following:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Try 1.&amp;nbsp;&lt;/P&gt;&lt;P&gt;libname athm&amp;nbsp; "C:\Users\Trial";&lt;/P&gt;&lt;P&gt;%macro do_yr(X,MY,s,e);&lt;BR /&gt;%do i=&amp;amp;s %to &amp;amp;e;&lt;BR /&gt;proc sql;&lt;BR /&gt;create table &amp;amp;x&amp;amp;i as&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; select&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; sum(Num) as Num,&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; sum(Denom) as &amp;nbsp;Den,&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;sum(Num)/sum(Denom) as rate,&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;amp;MY,&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;amp;i as RY&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; from athm.&amp;amp;X._reportdata_allyears_&amp;amp;i&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; where &amp;nbsp;Result="All"&lt;BR /&gt;group by &amp;nbsp;&amp;amp;MY&amp;nbsp;&lt;BR /&gt;quit; ;&lt;BR /&gt;%end;&lt;BR /&gt;&lt;BR /&gt;data &amp;amp;X;&lt;BR /&gt;set&lt;BR /&gt;%do j=&amp;amp;s %to &amp;amp;e %by 1;&lt;BR /&gt;&amp;amp;X&amp;amp;j&lt;BR /&gt;%if j=" " %then delete;&lt;/P&gt;&lt;P&gt;%end;&lt;BR /&gt;;run;&lt;/P&gt;&lt;P&gt;%mend do_year;&lt;BR /&gt;%do_year(AB,Year,2012,2016)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Try 2.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro convert(Y,s,e);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/*Create datasets with a common fields and formats*/&lt;/P&gt;&lt;P&gt;data&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;%do i=&amp;amp;s %to &amp;amp;e %by 1;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;amp;Y_reportdata_allyears_Trial$i;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/* Reading many data sets to SAS workspace from the library ATHM*/&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;set athm.&lt;BR /&gt;%do i=&amp;amp;s %to &amp;amp;e %by 1;&lt;BR /&gt;&amp;amp;Y_reportdata_allyears_&amp;amp;i;&lt;BR /&gt;rename Numerator=Num;&lt;BR /&gt;rename Denominator=Deno;&lt;BR /&gt;year1=put(year,4.);&lt;BR /&gt;drop year;&lt;BR /&gt;rename Year1=year;&lt;BR /&gt;format year $4.;&lt;BR /&gt;run;&lt;BR /&gt;%end;&lt;BR /&gt;%end;&lt;BR /&gt;%mend convert;&lt;BR /&gt;%convert(AB,2012,2016);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/*Try 1. works for some but not all. &amp;nbsp;Try 2.&amp;nbsp;Only create error message.*/&lt;/P&gt;&lt;P&gt;/*Please let me know if you have any questions. I will try to make a clear descriptions of the problems. I need your expertise to make this work. I'm open to suggestions and&amp;nbsp;alternative&amp;nbsp;apporaches;*/&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 18 Oct 2016 15:48:16 GMT</pubDate>
    <dc:creator>kllamitarey</dc:creator>
    <dc:date>2016-10-18T15:48:16Z</dc:date>
    <item>
      <title>SAS macro for reading various datasets with different formats and field name</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/SAS-macro-for-reading-various-datasets-with-different-formats/m-p/305420#M8715</link>
      <description>&lt;P&gt;I want &amp;nbsp;a macro that allows to read sas dataset from a library 'athm'. I need a macro coz&amp;nbsp;I have about more than &amp;nbsp;50 sas datasets &amp;nbsp;&amp;amp;&lt;SPAN&gt;X._reportdata_allyears_&amp;amp;i &amp;nbsp;and create a &amp;nbsp;data table &amp;nbsp;with common fields and later do some summary statistics. To break down, I want to run for 2012 to 2016.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Problem: Some of the tables have different coulmn names( such as &amp;nbsp;Numerator , num ,N ,&amp;nbsp;Nu, nume ) to mean the same thing. For example AB_reportdata_allyears_2012 has &amp;nbsp;a field &amp;nbsp;Numerator &amp;nbsp;and AB&lt;SPAN&gt;_reportdata_allyears_2013 has Num &amp;nbsp;to mean the same thing.&amp;nbsp;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN&gt;In one&amp;nbsp;dataset, the column 'Year ' is character and in other dataset, the column 'Year' is numeric. I want to make&amp;nbsp;year to &amp;nbsp;a character value for all datasets.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried the following:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Try 1.&amp;nbsp;&lt;/P&gt;&lt;P&gt;libname athm&amp;nbsp; "C:\Users\Trial";&lt;/P&gt;&lt;P&gt;%macro do_yr(X,MY,s,e);&lt;BR /&gt;%do i=&amp;amp;s %to &amp;amp;e;&lt;BR /&gt;proc sql;&lt;BR /&gt;create table &amp;amp;x&amp;amp;i as&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; select&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; sum(Num) as Num,&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; sum(Denom) as &amp;nbsp;Den,&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;sum(Num)/sum(Denom) as rate,&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;amp;MY,&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;amp;i as RY&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; from athm.&amp;amp;X._reportdata_allyears_&amp;amp;i&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; where &amp;nbsp;Result="All"&lt;BR /&gt;group by &amp;nbsp;&amp;amp;MY&amp;nbsp;&lt;BR /&gt;quit; ;&lt;BR /&gt;%end;&lt;BR /&gt;&lt;BR /&gt;data &amp;amp;X;&lt;BR /&gt;set&lt;BR /&gt;%do j=&amp;amp;s %to &amp;amp;e %by 1;&lt;BR /&gt;&amp;amp;X&amp;amp;j&lt;BR /&gt;%if j=" " %then delete;&lt;/P&gt;&lt;P&gt;%end;&lt;BR /&gt;;run;&lt;/P&gt;&lt;P&gt;%mend do_year;&lt;BR /&gt;%do_year(AB,Year,2012,2016)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Try 2.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro convert(Y,s,e);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/*Create datasets with a common fields and formats*/&lt;/P&gt;&lt;P&gt;data&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;%do i=&amp;amp;s %to &amp;amp;e %by 1;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;amp;Y_reportdata_allyears_Trial$i;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/* Reading many data sets to SAS workspace from the library ATHM*/&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;set athm.&lt;BR /&gt;%do i=&amp;amp;s %to &amp;amp;e %by 1;&lt;BR /&gt;&amp;amp;Y_reportdata_allyears_&amp;amp;i;&lt;BR /&gt;rename Numerator=Num;&lt;BR /&gt;rename Denominator=Deno;&lt;BR /&gt;year1=put(year,4.);&lt;BR /&gt;drop year;&lt;BR /&gt;rename Year1=year;&lt;BR /&gt;format year $4.;&lt;BR /&gt;run;&lt;BR /&gt;%end;&lt;BR /&gt;%end;&lt;BR /&gt;%mend convert;&lt;BR /&gt;%convert(AB,2012,2016);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/*Try 1. works for some but not all. &amp;nbsp;Try 2.&amp;nbsp;Only create error message.*/&lt;/P&gt;&lt;P&gt;/*Please let me know if you have any questions. I will try to make a clear descriptions of the problems. I need your expertise to make this work. I'm open to suggestions and&amp;nbsp;alternative&amp;nbsp;apporaches;*/&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Oct 2016 15:48:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/SAS-macro-for-reading-various-datasets-with-different-formats/m-p/305420#M8715</guid>
      <dc:creator>kllamitarey</dc:creator>
      <dc:date>2016-10-18T15:48:16Z</dc:date>
    </item>
    <item>
      <title>Re: SAS macro for reading various datasets with different formats and field name</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/SAS-macro-for-reading-various-datasets-with-different-formats/m-p/305510#M8725</link>
      <description>If you set a naming standard everything will be simpler. Rename using proc datasets or put views on top. Ultimately store all data on the same table which will minimise the need for complicated macro loop programming.</description>
      <pubDate>Tue, 18 Oct 2016 19:40:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/SAS-macro-for-reading-various-datasets-with-different-formats/m-p/305510#M8725</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2016-10-18T19:40:47Z</dc:date>
    </item>
    <item>
      <title>Re: SAS macro for reading various datasets with different formats and field name</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/SAS-macro-for-reading-various-datasets-with-different-formats/m-p/305540#M8727</link>
      <description>&lt;P&gt;If this were my project I would be strongly tempted to either rename in place as per &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13674"&gt;@LinusH﻿&lt;/a&gt;&amp;nbsp;and if not practical as others use the data sets to make copies and rename the variables. A control data set with the name of the original dataset, new data set, original variable name and new or corrected data set name in data set would let you use a data step with call execute to copy the original data to the new set and then rename the variables.&lt;/P&gt;</description>
      <pubDate>Tue, 18 Oct 2016 21:24:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/SAS-macro-for-reading-various-datasets-with-different-formats/m-p/305540#M8727</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-10-18T21:24:53Z</dc:date>
    </item>
  </channel>
</rss>

