<?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: function in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/function/m-p/467314#M119289</link>
    <description>&lt;P&gt;Here's code that does what I think you want, retrieving first_name in two ways:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data department;
infile '$HOME/sascommunity/department.csv' dlm=',' dsd termstr=CRLF firstobs=2;
input code_id $ department :$30. expenditure :comma. name :$30.;
run;

data want;
set department (keep=name);
last_name = scan(name,1,',');
first_name = left(scan(name,2,','));
first_name = substr(first_name,1,length(first_name)-2);
start_pos = indexc(name,',') + 2;
first_name_2 = substr(name,start_pos);
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The additional substr in&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;first_name = substr(first_name,1,length(first_name)-2);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;removes the country code.&lt;/P&gt;</description>
    <pubDate>Mon, 04 Jun 2018 07:48:08 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2018-06-04T07:48:08Z</dc:date>
    <item>
      <title>function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/function/m-p/467208#M119263</link>
      <description>&lt;P&gt;Create a new variable last name from name, find the starting position of first and create new variable first name from name variable using the positions found in previous question.&lt;EM&gt;Hint: Use SUBSTR function&lt;/EM&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 03 Jun 2018 08:26:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/function/m-p/467208#M119263</guid>
      <dc:creator>GAUTAMDVN</dc:creator>
      <dc:date>2018-06-03T08:26:00Z</dc:date>
    </item>
    <item>
      <title>Re: function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/function/m-p/467211#M119265</link>
      <description>&lt;P&gt;Post the code and log you already have, and show where it does not meet your expectations.&lt;/P&gt;</description>
      <pubDate>Sun, 03 Jun 2018 10:46:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/function/m-p/467211#M119265</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-06-03T10:46:54Z</dc:date>
    </item>
    <item>
      <title>Re: function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/function/m-p/467214#M119267</link>
      <description>&lt;P&gt;DATA PART_A ;&lt;BR /&gt;SET LEARN.DEPARTMENT(KEEP = NAME) ;&lt;BR /&gt;LAST_NAME = SCAN(NAME,1);&lt;BR /&gt;RUN ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;DATA PART_B;&lt;BR /&gt;SET LEARN.DEPARTMENT (KEEP = NAME);&lt;BR /&gt;NAME = COMPRESS(NAME,,'P') ;&lt;BR /&gt;FIRST_NAME = SCAN(NAME,2,'');&lt;BR /&gt;CHAR = SUBSTR(FIRST_NAME,1,1) ;&lt;BR /&gt;IF INDEX(CHAR,'') &amp;gt; 0 ;&lt;BR /&gt;RUN ;&lt;/P&gt;</description>
      <pubDate>Sun, 03 Jun 2018 11:39:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/function/m-p/467214#M119267</guid>
      <dc:creator>GAUTAMDVN</dc:creator>
      <dc:date>2018-06-03T11:39:48Z</dc:date>
    </item>
    <item>
      <title>Re: function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/function/m-p/467215#M119268</link>
      <description>&lt;P&gt;Hi Kurt,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Part a is done by me but in second part I've tried to find the starting position of first name as mentioned below but not able to do the&amp;nbsp; same.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;DATA PART_B;&lt;BR /&gt;SET LEARN.DEPARTMENT (KEEP = NAME);&lt;BR /&gt;NAME = COMPRESS(NAME,,'P') ;&lt;BR /&gt;FIRST_NAME = SCAN(NAME,2,'');&lt;BR /&gt;CHAR = SUBSTR(FIRST_NAME,1,1) ;&lt;BR /&gt;IF INDEX(CHAR,'') &amp;gt; 0 ;&lt;BR /&gt;RUN ;&lt;/P&gt;</description>
      <pubDate>Sun, 03 Jun 2018 11:41:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/function/m-p/467215#M119268</guid>
      <dc:creator>GAUTAMDVN</dc:creator>
      <dc:date>2018-06-03T11:41:40Z</dc:date>
    </item>
    <item>
      <title>Re: function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/function/m-p/467217#M119270</link>
      <description>&lt;P&gt;I am not sure, if I understood the requirement correctly, but as far as i understood this is the solution :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data new;&lt;BR /&gt;set department;&lt;BR /&gt;last_name= scan(names,2,',');&lt;BR /&gt;pos=indexc(names,',');&lt;BR /&gt;first_name = substr(names,1,pos-1);&lt;BR /&gt;drop pos;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Sun, 03 Jun 2018 11:54:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/function/m-p/467217#M119270</guid>
      <dc:creator>ruchi11dec</dc:creator>
      <dc:date>2018-06-03T11:54:42Z</dc:date>
    </item>
    <item>
      <title>Re: function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/function/m-p/467314#M119289</link>
      <description>&lt;P&gt;Here's code that does what I think you want, retrieving first_name in two ways:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data department;
infile '$HOME/sascommunity/department.csv' dlm=',' dsd termstr=CRLF firstobs=2;
input code_id $ department :$30. expenditure :comma. name :$30.;
run;

data want;
set department (keep=name);
last_name = scan(name,1,',');
first_name = left(scan(name,2,','));
first_name = substr(first_name,1,length(first_name)-2);
start_pos = indexc(name,',') + 2;
first_name_2 = substr(name,start_pos);
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The additional substr in&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;first_name = substr(first_name,1,length(first_name)-2);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;removes the country code.&lt;/P&gt;</description>
      <pubDate>Mon, 04 Jun 2018 07:48:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/function/m-p/467314#M119289</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-06-04T07:48:08Z</dc:date>
    </item>
    <item>
      <title>Re: function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/function/m-p/467338#M119294</link>
      <description>Please check the below:&lt;BR /&gt;PROC IMPORT DATAFILE='/folders/myfolders/sasuser.v94/flat files/test/department.csv'&lt;BR /&gt;DBMS=CSV&lt;BR /&gt;OUT=TEMP&lt;BR /&gt;REPLACE&lt;BR /&gt;;&lt;BR /&gt;RUN;&lt;BR /&gt;&lt;BR /&gt;DATA TEMP;&lt;BR /&gt;SET TEMP;&lt;BR /&gt;&lt;BR /&gt;Last_Name=SCAN(Name,1,',');&lt;BR /&gt;Tmp_fst_nm=SCAN(Name,2,',');&lt;BR /&gt;&lt;BR /&gt;Fst_Nm= SUBSTR(Tmp_fst_nm,1,LENGTH(Tmp_fst_nm)-2);&lt;BR /&gt;&lt;BR /&gt;DROP Tmp_fst_nm;&lt;BR /&gt;RUN;&lt;BR /&gt;</description>
      <pubDate>Mon, 04 Jun 2018 10:30:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/function/m-p/467338#M119294</guid>
      <dc:creator>mahesh146</dc:creator>
      <dc:date>2018-06-04T10:30:58Z</dc:date>
    </item>
  </channel>
</rss>

