<?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: set data sets and create new variable with source name in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/set-data-sets-and-create-new-variable-with-source-name/m-p/694543#M211828</link>
    <description>&lt;P&gt;Try this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data final;
    set ABC1912 
        ABC2001  
        ABC2002  
        ABC2003 indsname=ds;
    newvar = compress(scan(ds,2,'.'),, 'kd');
Run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 27 Oct 2020 12:47:31 GMT</pubDate>
    <dc:creator>PeterClemmensen</dc:creator>
    <dc:date>2020-10-27T12:47:31Z</dc:date>
    <item>
      <title>set data sets and create new variable with source name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/set-data-sets-and-create-new-variable-with-source-name/m-p/694541#M211826</link>
      <description>&lt;P&gt;hello&lt;/P&gt;
&lt;P&gt;I am using set statement to concatenate data sets.&lt;/P&gt;
&lt;P&gt;I want to create a new column with information of source data set (value will be from letter 4 till letter 7 in data set name. for example: if source data set is ABC1912 then value will be 1912 and so on&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
Data ABC1912;
input x;
cards;
1
2
;
run;
Data ABC2001;
input x;
cards;
11
22
;
run;
Data ABC2002;
input x;
cards;
13
22
;
run;
Data ABC2003;
input x;
cards;
1
23
;
run;
Data final;
set ABC1912 ABC2001  ABC2002  ABC2003;
/*I want to create a new variable that will get value from the source data set name:
If the observation from data set ABC1912 then will get value 1912
If the observation from data set ABC2001 then will get value 2001
If the observation from data set ABC2002 then will get value 2002
If the observation from data set ABC2003 then will get value 2003*/
Run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 27 Oct 2020 12:42:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/set-data-sets-and-create-new-variable-with-source-name/m-p/694541#M211826</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2020-10-27T12:42:46Z</dc:date>
    </item>
    <item>
      <title>Re: set data sets and create new variable with source name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/set-data-sets-and-create-new-variable-with-source-name/m-p/694543#M211828</link>
      <description>&lt;P&gt;Try this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data final;
    set ABC1912 
        ABC2001  
        ABC2002  
        ABC2003 indsname=ds;
    newvar = compress(scan(ds,2,'.'),, 'kd');
Run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 27 Oct 2020 12:47:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/set-data-sets-and-create-new-variable-with-source-name/m-p/694543#M211828</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2020-10-27T12:47:31Z</dc:date>
    </item>
    <item>
      <title>Re: set data sets and create new variable with source name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/set-data-sets-and-create-new-variable-with-source-name/m-p/694545#M211830</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data final;
set ABC1912 ABC2001  ABC2002  ABC2003 indsname=indsname;
source=substr(scan(indsname,2),4);
Run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 27 Oct 2020 12:49:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/set-data-sets-and-create-new-variable-with-source-name/m-p/694545#M211830</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-10-27T12:49:31Z</dc:date>
    </item>
    <item>
      <title>Re: set data sets and create new variable with source name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/set-data-sets-and-create-new-variable-with-source-name/m-p/694596#M211836</link>
      <description>&lt;P&gt;Great!&lt;/P&gt;
&lt;P&gt;Now all is clear.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 28 Oct 2020 05:59:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/set-data-sets-and-create-new-variable-with-source-name/m-p/694596#M211836</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2020-10-28T05:59:46Z</dc:date>
    </item>
    <item>
      <title>Re: set data sets and create new variable with source name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/set-data-sets-and-create-new-variable-with-source-name/m-p/694597#M211837</link>
      <description>&lt;P&gt;Can you please explain why you used number 2 ?&lt;/P&gt;
&lt;P&gt;What is ds?&lt;/P&gt;
&lt;P&gt;Does 'kd' means to take only digits?&lt;/P&gt;
&lt;PRE class="language-sas"&gt;&lt;CODE&gt;compress(scan(ds,2,'.'),, 'kd');&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Oct 2020 14:43:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/set-data-sets-and-create-new-variable-with-source-name/m-p/694597#M211837</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2020-10-27T14:43:05Z</dc:date>
    </item>
    <item>
      <title>Re: set data sets and create new variable with source name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/set-data-sets-and-create-new-variable-with-source-name/m-p/694606#M211841</link>
      <description>&lt;P&gt;The dataset name as returned into the INDSNAME= variable contains the library and dataset name, so the SCAN function extracts the dataset name. The &lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.4&amp;amp;docsetId=lefunctionsref&amp;amp;docsetTarget=n0fcshr0ir3h73n1b845c4aq58hz.htm&amp;amp;locale=en" target="_blank" rel="noopener"&gt;COMPRESS&lt;/A&gt; then extracts the part you are interested in, as you suspected (see section "modifier").&lt;/P&gt;</description>
      <pubDate>Tue, 27 Oct 2020 15:11:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/set-data-sets-and-create-new-variable-with-source-name/m-p/694606#M211841</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-10-27T15:11:42Z</dc:date>
    </item>
  </channel>
</rss>

