<?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: substract strings from dataset name and put it in a variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/substract-strings-from-dataset-name-and-put-it-in-a-variable/m-p/684537#M207456</link>
    <description>OMG THAT WAS IT I'M SO STUPID THAAAANKS</description>
    <pubDate>Thu, 17 Sep 2020 09:58:12 GMT</pubDate>
    <dc:creator>skavli</dc:creator>
    <dc:date>2020-09-17T09:58:12Z</dc:date>
    <item>
      <title>substract strings from dataset name and put it in a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/substract-strings-from-dataset-name-and-put-it-in-a-variable/m-p/684523#M207442</link>
      <description>&lt;P&gt;Hi i have a list of files that i import using my macro, inside this macro there is also data step that I want to use my tables names to extract months and years and add them to those tables, so i used the substr function, but i receive this error for each iteration&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;NOTE: Numeric values have been converted to character values at the places given by: (Line):(Column).
      26:1   26:1   
NOTE: Character values have been converted to numeric values at the places given by: (Line):(Column).
      26:9   
NOTE: Variable Jan20 is uninitialized.
NOTE: Invalid second argument to function SUBSTR at ligne 65483 colonne 223.&lt;/PRE&gt;&lt;P&gt;Here is my code :&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let rep = \\sfdrza\QQQ\adkjf\AAA\BBB\CCC\sdsdt\DDD

%let y20 = Jan20 Feb20;

/*Import*/
options msglevel=I;
options mprint;
%macro boucle_doCC(in);
	%local i s;

	%do i=1 %to %sysfunc(countw(&amp;amp;in.,%str( )));
		%let s&amp;amp;i.=%scan(&amp;amp;in.,&amp;amp;i.,%str( ));

		proc import datafile ="&amp;amp;rep.\&amp;amp;&amp;amp;s&amp;amp;i...xlsx"
			out=&amp;amp;&amp;amp;s&amp;amp;i..
			dbms=xlsx replace;
			getnames=yes;
		run;
		
		data &amp;amp;&amp;amp;s&amp;amp;i..(keep= Brand Segment DC Trade:);
			set &amp;amp;&amp;amp;s&amp;amp;i..;

			if missing(Brand) then delete;

			/*ajout des colonnes mois et année*/
			year=substr(&amp;amp;&amp;amp;s&amp;amp;i.,-1, 2);
			month=substr(&amp;amp;&amp;amp;s&amp;amp;i..,1, 3);
		run;

	%end;
%mend boucle_doCC;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 17 Sep 2020 09:13:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/substract-strings-from-dataset-name-and-put-it-in-a-variable/m-p/684523#M207442</guid>
      <dc:creator>skavli</dc:creator>
      <dc:date>2020-09-17T09:13:05Z</dc:date>
    </item>
    <item>
      <title>Re: substract strings from dataset name and put it in a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/substract-strings-from-dataset-name-and-put-it-in-a-variable/m-p/684528#M207447</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If I'm guessing right you are using the `y20` macrovariable as an input to the macro as `in` macrovariable?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1) substr() function can not have negative value as a second parameter:&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;year=substr(&amp;amp;&amp;amp;s&amp;amp;i.,-1, 2);&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2) &amp;amp;&amp;amp;s&amp;amp;i resolves to&amp;nbsp;Jan20 and substr() expect to get text string, like "Jan20"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Maybe try something like this:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;year=substr("&amp;amp;&amp;amp;s&amp;amp;i.", 4, 2);
month=substr("&amp;amp;&amp;amp;s&amp;amp;i.", 1, 3);&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 17 Sep 2020 09:42:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/substract-strings-from-dataset-name-and-put-it-in-a-variable/m-p/684528#M207447</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2020-09-17T09:42:35Z</dc:date>
    </item>
    <item>
      <title>Re: substract strings from dataset name and put it in a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/substract-strings-from-dataset-name-and-put-it-in-a-variable/m-p/684530#M207449</link>
      <description>&lt;P&gt;As &amp;amp;&amp;amp;s&amp;amp;i, the filename. is a literal and not a variable name,&lt;/P&gt;
&lt;P&gt;it should be enclosed by double quotes (not single quotes) to be&lt;/P&gt;
&lt;P&gt;resolved as a literal. For example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;year = substtr("&amp;amp;&amp;amp;s&amp;amp;i", &amp;lt;start&amp;gt;, &amp;lt;length&amp;gt;);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;was it a typo assigning start =&lt;STRONG&gt; -1&lt;/STRONG&gt; for subtracting the year ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 17 Sep 2020 09:48:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/substract-strings-from-dataset-name-and-put-it-in-a-variable/m-p/684530#M207449</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2020-09-17T09:48:16Z</dc:date>
    </item>
    <item>
      <title>Re: substract strings from dataset name and put it in a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/substract-strings-from-dataset-name-and-put-it-in-a-variable/m-p/684532#M207451</link>
      <description>&lt;P&gt;I did not know that substr can't go from right to left, i tried your code but does not seem to work unfortunately&lt;/P&gt;</description>
      <pubDate>Thu, 17 Sep 2020 09:51:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/substract-strings-from-dataset-name-and-put-it-in-a-variable/m-p/684532#M207451</guid>
      <dc:creator>skavli</dc:creator>
      <dc:date>2020-09-17T09:51:13Z</dc:date>
    </item>
    <item>
      <title>Re: substract strings from dataset name and put it in a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/substract-strings-from-dataset-name-and-put-it-in-a-variable/m-p/684533#M207452</link>
      <description>No i thought that substr could go from right to left</description>
      <pubDate>Thu, 17 Sep 2020 09:51:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/substract-strings-from-dataset-name-and-put-it-in-a-variable/m-p/684533#M207452</guid>
      <dc:creator>skavli</dc:creator>
      <dc:date>2020-09-17T09:51:43Z</dc:date>
    </item>
    <item>
      <title>Re: substract strings from dataset name and put it in a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/substract-strings-from-dataset-name-and-put-it-in-a-variable/m-p/684534#M207453</link>
      <description>&lt;P&gt;Share modified code and full log. It will be easier to figure out what's wrong.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;B&lt;/P&gt;</description>
      <pubDate>Thu, 17 Sep 2020 09:53:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/substract-strings-from-dataset-name-and-put-it-in-a-variable/m-p/684534#M207453</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2020-09-17T09:53:23Z</dc:date>
    </item>
    <item>
      <title>Re: substract strings from dataset name and put it in a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/substract-strings-from-dataset-name-and-put-it-in-a-variable/m-p/684535#M207454</link>
      <description>&lt;P&gt;By the way, when you use the `(keep= Brand Segment DC Trade:)` you are dropping year and month from your data&amp;nbsp;&lt;/P&gt;
&lt;P&gt;B&lt;/P&gt;</description>
      <pubDate>Thu, 17 Sep 2020 09:56:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/substract-strings-from-dataset-name-and-put-it-in-a-variable/m-p/684535#M207454</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2020-09-17T09:56:26Z</dc:date>
    </item>
    <item>
      <title>Re: substract strings from dataset name and put it in a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/substract-strings-from-dataset-name-and-put-it-in-a-variable/m-p/684537#M207456</link>
      <description>OMG THAT WAS IT I'M SO STUPID THAAAANKS</description>
      <pubDate>Thu, 17 Sep 2020 09:58:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/substract-strings-from-dataset-name-and-put-it-in-a-variable/m-p/684537#M207456</guid>
      <dc:creator>skavli</dc:creator>
      <dc:date>2020-09-17T09:58:12Z</dc:date>
    </item>
    <item>
      <title>Re: substract strings from dataset name and put it in a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/substract-strings-from-dataset-name-and-put-it-in-a-variable/m-p/684538#M207457</link>
      <description>&lt;P&gt;hers is "working" version on some fake test data:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* test data */
data Jan20 Feb20 ;
input Brand Segment DC Trade;
cards;
1 2 3 4
5 6 7 8
;
run;




%let rep = \\sfdrza\QQQ\adkjf\AAA\BBB\CCC\sdsdt\DDD ;

%let y20 = Jan20 Feb20;


/*Import*/
options msglevel=I;
options mprint;
%macro boucle_doCC(in);
	%local i s;

	%do i=1 %to %sysfunc(countw(&amp;amp;in.,%str( )));
		%let s&amp;amp;i.=%scan(&amp;amp;in.,&amp;amp;i.,%str( ));

    /* commented out to avoid importing */
    /*
		proc import datafile ="&amp;amp;rep.\&amp;amp;&amp;amp;s&amp;amp;i...xlsx"
			out=&amp;amp;&amp;amp;s&amp;amp;i..
			dbms=xlsx replace;
			getnames=yes;
		run;
    */
		
		data &amp;amp;&amp;amp;s&amp;amp;i..(keep= year month Brand Segment DC Trade:);
			set &amp;amp;&amp;amp;s&amp;amp;i..;

			if missing(Brand) then delete;

			/*ajout des colonnes mois et année*/
			year=substr("&amp;amp;&amp;amp;s&amp;amp;i.", 4, 2);
			month=substr("&amp;amp;&amp;amp;s&amp;amp;i.", 1, 3);
		run;

	%end;
%mend boucle_doCC;

%boucle_doCC(&amp;amp;y20.)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;B&lt;/P&gt;</description>
      <pubDate>Thu, 17 Sep 2020 10:00:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/substract-strings-from-dataset-name-and-put-it-in-a-variable/m-p/684538#M207457</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2020-09-17T10:00:27Z</dc:date>
    </item>
    <item>
      <title>Re: substract strings from dataset name and put it in a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/substract-strings-from-dataset-name-and-put-it-in-a-variable/m-p/684539#M207458</link>
      <description>&lt;P&gt;i get the year but not the month &lt;span class="lia-unicode-emoji" title=":confused_face:"&gt;😕&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;NOTE: Character values have been converted to numeric values at the places given by: (Line):(Column).
38                                                         Le Système SAS                         10:06 Thursday, September 17, 2020

      29:48   
WARNING: The variable 'D/C'n in the DROP, KEEP, or RENAME list has never been referenced.
NOTE: Invalid numeric data, 'Feb' , at ligne 29 colonne 48.
Brand=Hyundai i10 Segment=A DC=1200 Trade-in=  E=  Detail=  Entry MSRP=10790 Monthly=115 Dpmt=1300 Month=. Mileage=50,000 Mtnce ?= 
Trim=1.0 67 ECO Initia Offer Launching date( Blank, i=01.02.2020 End Date (if decided)=29.02.2020 Private M/S &amp;amp; trend= 
Detail_1=Longest promo from Hyundai ( 61 months) year=20 _ERROR_=1 _N_=1&lt;/PRE&gt;</description>
      <pubDate>Thu, 17 Sep 2020 10:01:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/substract-strings-from-dataset-name-and-put-it-in-a-variable/m-p/684539#M207458</guid>
      <dc:creator>skavli</dc:creator>
      <dc:date>2020-09-17T10:01:10Z</dc:date>
    </item>
    <item>
      <title>Re: substract strings from dataset name and put it in a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/substract-strings-from-dataset-name-and-put-it-in-a-variable/m-p/684540#M207459</link>
      <description>&lt;P&gt;&lt;SPAN&gt;"An expert is a person who has made all the mistakes that can be made in a very narrow field." Niels Bohr&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 17 Sep 2020 10:01:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/substract-strings-from-dataset-name-and-put-it-in-a-variable/m-p/684540#M207459</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2020-09-17T10:01:25Z</dc:date>
    </item>
  </channel>
</rss>

