<?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: Proc import to import file with different date in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Proc-import-to-import-file-with-different-date/m-p/539196#M148517</link>
    <description>&lt;P&gt;Thank you&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 28 Feb 2019 02:50:11 GMT</pubDate>
    <dc:creator>imdickson</dc:creator>
    <dc:date>2019-02-28T02:50:11Z</dc:date>
    <item>
      <title>Proc import to import file with different date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-import-to-import-file-with-different-date/m-p/538977#M148423</link>
      <description>&lt;P&gt;Hi all. I was given some csv files with the following naming convertion:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;re_jan2018.csv
re_feb2018.csv
re_mac2018.csv
re_apr2018.csv
re_may2018.csv
re_jun2018.csv
re_jul2018.csv
re_aug2018.csv
re_sep2018.csv
re_oct2018.csv
re_nov2018.csv
re_dec2018.csv
re_jan2019.csv
re_feb2019.csv

There will be a new csv file with new month, monthly, in above naming convention&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The problem is, user will key in the period in yymmn6. format, which will look like this, everytime:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;201801 &amp;lt;- this indicate jan2018
201902 &amp;lt;- this indicate feb2019&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;My expectation is as below:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;1) User will input period, eg, 201808
2) script will then change that to aug2018 and assign this into proc import file statement to import aug2018.csv file&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I want to import the csv file according to user prompt in above format.&lt;/P&gt;&lt;P&gt;I have following code (that doesnt work)&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let period=201812;
%macro convertdate();
data convertdate;
year=substr("&amp;amp;period",1,4);
month=substr("&amp;amp;period",5,2);
if month='01' then newmonth='jan';
if month='02' then newmonth='feb';
if month='03' then newmonth='mac';
if month='04' then newmonth='apr';
if month='05' then newmonth='may';
if month='06' then newmonth='jun';
if month='07' then newmonth='jul';
if month='08' then newmonth='aug';
if month='09' then newmonth='sep';
if month='10' then newmonth='oct';
if month='11' then newmonth='nov';
if month='12' then newmonth='dec';

run;

/*Assign convertdate the only distinct record into macro, then set as the data step for proc import*/
%if month='01' %then %do;
	%let newmonth=jan;
%end;
/*if month='02' then newmonth='feb';*/
/*if month='03' then newmonth='mac';*/
/*if month='04' then newmonth='apr';*/
/*if month='05' then newmonth='may';*/
/*if month='06' then newmonth='jun';*/
/*if month='07' then newmonth='jul';*/
/*if month='08' then newmonth='aug';*/
/*if month='09' then newmonth='sep';*/
/*if month='10' then newmonth='oct';*/
/*if month='11' then newmonth='nov';*/
/*if month='12' then newmonth='dec';*/


/*proc import and remaining transformation from existing script*/
proc import out=rmr_raw_source_jan2018
  file="/sasdata/source/user_files/re_&amp;amp;newmonth.2018.csv"

  dbms=csv replace;
  sheet="re_&amp;amp;newmonth.2018";
  getnames=no;
  dbsaslabel=none;
run;

%mend;
%convertdate;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;and my log:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;WARNING: Apparent symbolic reference NEWMONTH not resolved.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Can anyone tell me a better way of doing it?&lt;/P&gt;</description>
      <pubDate>Wed, 27 Feb 2019 14:45:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-import-to-import-file-with-different-date/m-p/538977#M148423</guid>
      <dc:creator>imdickson</dc:creator>
      <dc:date>2019-02-27T14:45:22Z</dc:date>
    </item>
    <item>
      <title>Re: Proc import to import file with different date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-import-to-import-file-with-different-date/m-p/538984#M148426</link>
      <description>&lt;P&gt;You don't need to code for each month, simply:&lt;/P&gt;
&lt;PRE&gt;%let period=201812;

data _null_;
  call symput('dte',substr(put(input(cats("&amp;amp;period.","01"),yymmdd10.),date9.),3));
run;&lt;BR /&gt;&lt;BR /&gt;proc import file=".../re_&amp;amp;dte..csv"...&lt;/PRE&gt;
&lt;P&gt;You can lower case if need be.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Next up, dont use proc import to import data in a production environment.&amp;nbsp; Write a datastep import (you can take the generated code from the log) and specifically set it per your known data structure.&amp;nbsp; Proc import guesses the data format, so you can end up with different structure each time.&lt;/P&gt;</description>
      <pubDate>Wed, 27 Feb 2019 14:37:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-import-to-import-file-with-different-date/m-p/538984#M148426</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2019-02-27T14:37:24Z</dc:date>
    </item>
    <item>
      <title>Re: Proc import to import file with different date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-import-to-import-file-with-different-date/m-p/538987#M148428</link>
      <description>&lt;P&gt;One of your CSV files has a different format of the file name:&amp;nbsp;re_oct_2018.csv, that underscore between the month and year will be a problem, and my code won't address this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Next, the idea of mixing and matching data step commands with macro&amp;nbsp; commands will work, but you have to be&amp;nbsp;&lt;EM&gt;extremely&amp;nbsp;&lt;/EM&gt;careful when you do this. It is very easy to try to use data step commands on macro variables, or macro variables where you really mean data step variables, and this is a cause of problems.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any advice should begin with this: first, get the code working WITHOUT macros and WITHOUT macros variables on one or two cases, and then turning it into a macro ought to be much easier. You haven't done this.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Lastly, learn to use the SAS date/time functions, formats and informats and your life will be much much easier than writing out code for each month.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's a simple solution for the case where period has the value 201812&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let period=201812;

data _null_;
	monthyr=input("&amp;amp;period",yymmn6.);
	call symputx('month',cats(put(monthyr,worddate3.),year(monthyr)));
run;
%put &amp;amp;=month;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Feb 2019 15:16:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-import-to-import-file-with-different-date/m-p/538987#M148428</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-02-27T15:16:21Z</dc:date>
    </item>
    <item>
      <title>Re: Proc import to import file with different date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-import-to-import-file-with-different-date/m-p/539196#M148517</link>
      <description>&lt;P&gt;Thank you&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Feb 2019 02:50:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-import-to-import-file-with-different-date/m-p/539196#M148517</guid>
      <dc:creator>imdickson</dc:creator>
      <dc:date>2019-02-28T02:50:11Z</dc:date>
    </item>
  </channel>
</rss>

