<?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: Translating a code from SPSS to SAS in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Translating-a-code-from-SPSS-to-SAS/m-p/753556#M237529</link>
    <description>&lt;P&gt;Literal translation if I remember my SPSS correctly:&lt;/P&gt;
&lt;PRE&gt;length new_var $ 200; 
if index(var,'?')&amp;gt;0 then new_var = substr(var,1,index(var,'?')-1);
else new_var=var;&lt;/PRE&gt;
&lt;P&gt;However if the purpose is to get everything before a single ? in the data&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;new_var= scan(var,1,'?');&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The '?' tells SAS to only consider a question mark as a delimiter between string sections. If one is not found then the entire string is returned. New_var would inherit the length of the VAR variable if that is the first use. If that isn't desired then use a length statement to set an explicit length.&lt;/P&gt;</description>
    <pubDate>Mon, 12 Jul 2021 17:16:25 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2021-07-12T17:16:25Z</dc:date>
    <item>
      <title>Translating a code from SPSS to SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Translating-a-code-from-SPSS-to-SAS/m-p/753544#M237523</link>
      <description>&lt;P&gt;I work with SAS and the other members of my team work with SPSS and I usually need to translate codes between SPSS and SAS. I wonder if someone may help me to translate this. I want to create &lt;FONT color="#FF6600"&gt;new_var&lt;/FONT&gt; from &lt;FONT color="#0000FF"&gt;var&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000000"&gt;I appreciate any hint that may help me to translate this. Thanks&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;STRING &lt;FONT color="#FF6600"&gt;new_var&lt;/FONT&gt;&amp;nbsp;(A200).&lt;/P&gt;
&lt;P&gt;EXECUTE.&lt;/P&gt;
&lt;P&gt;COMPUTE &lt;FONT color="#FF6600"&gt;new_var&lt;/FONT&gt;=CHAR.SUBSTR(&lt;FONT color="#0000FF"&gt;var&lt;/FONT&gt;,1,CHAR.INDEX(&lt;FONT color="#0000FF"&gt;var&lt;/FONT&gt;,"?")-1).&lt;/P&gt;
&lt;P&gt;IF NOT(CHAR.INDEX(&lt;FONT color="#0000FF"&gt;var&lt;/FONT&gt;,"?")&amp;gt;0) &lt;FONT color="#FF6600"&gt;new_var&lt;/FONT&gt;&amp;nbsp;= &lt;FONT color="#0000FF"&gt;var&lt;/FONT&gt;.&lt;/P&gt;
&lt;P&gt;EXECUTE.&lt;/P&gt;</description>
      <pubDate>Mon, 12 Jul 2021 16:06:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Translating-a-code-from-SPSS-to-SAS/m-p/753544#M237523</guid>
      <dc:creator>Emma_at_SAS</dc:creator>
      <dc:date>2021-07-12T16:06:51Z</dc:date>
    </item>
    <item>
      <title>Re: Translating a code from SPSS to SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Translating-a-code-from-SPSS-to-SAS/m-p/753554#M237527</link>
      <description>&lt;P&gt;Hello Mary,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think I can guess approximately what this SPSS code does, but it would be better if you can explain it a little bit.&lt;/P&gt;
&lt;P&gt;Or specify some relevant examples of "var" and "new_var".&lt;/P&gt;
&lt;P&gt;That will make it easier for the majority of us to answer correctly.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;Koen&lt;/P&gt;</description>
      <pubDate>Mon, 12 Jul 2021 17:13:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Translating-a-code-from-SPSS-to-SAS/m-p/753554#M237527</guid>
      <dc:creator>sbxkoenk</dc:creator>
      <dc:date>2021-07-12T17:13:27Z</dc:date>
    </item>
    <item>
      <title>Re: Translating a code from SPSS to SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Translating-a-code-from-SPSS-to-SAS/m-p/753555#M237528</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/84351"&gt;@Emma_at_SAS&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I work with SAS and the other members of my team work with SPSS and I usually need to translate codes between SPSS and SAS. I wonder if someone may help me to translate this. I want to create &lt;FONT color="#FF6600"&gt;new_var&lt;/FONT&gt; from &lt;FONT color="#0000FF"&gt;var&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000000"&gt;I appreciate any hint that may help me to translate this. Thanks&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;STRING &lt;FONT color="#FF6600"&gt;new_var&lt;/FONT&gt;&amp;nbsp;(A200).&lt;/P&gt;
&lt;P&gt;EXECUTE.&lt;/P&gt;
&lt;P&gt;COMPUTE &lt;FONT color="#FF6600"&gt;new_var&lt;/FONT&gt;=CHAR.SUBSTR(&lt;FONT color="#0000FF"&gt;var&lt;/FONT&gt;,1,CHAR.INDEX(&lt;FONT color="#0000FF"&gt;var&lt;/FONT&gt;,"?")-1).&lt;/P&gt;
&lt;P&gt;IF NOT(CHAR.INDEX(&lt;FONT color="#0000FF"&gt;var&lt;/FONT&gt;,"?")&amp;gt;0) &lt;FONT color="#FF6600"&gt;new_var&lt;/FONT&gt;&amp;nbsp;= &lt;FONT color="#0000FF"&gt;var&lt;/FONT&gt;.&lt;/P&gt;
&lt;P&gt;EXECUTE.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;No one said what the code is supposed to do?&lt;/P&gt;
&lt;P&gt;Looks like it is just trimming the data to the the first part before the first question mark.&amp;nbsp; You could try to translate the existing logic into SAS, but why not just use the SCAN() function?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;length new_var $200;
new_var=scan(var,1,'?');&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 12 Jul 2021 17:14:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Translating-a-code-from-SPSS-to-SAS/m-p/753555#M237528</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-07-12T17:14:55Z</dc:date>
    </item>
    <item>
      <title>Re: Translating a code from SPSS to SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Translating-a-code-from-SPSS-to-SAS/m-p/753556#M237529</link>
      <description>&lt;P&gt;Literal translation if I remember my SPSS correctly:&lt;/P&gt;
&lt;PRE&gt;length new_var $ 200; 
if index(var,'?')&amp;gt;0 then new_var = substr(var,1,index(var,'?')-1);
else new_var=var;&lt;/PRE&gt;
&lt;P&gt;However if the purpose is to get everything before a single ? in the data&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;new_var= scan(var,1,'?');&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The '?' tells SAS to only consider a question mark as a delimiter between string sections. If one is not found then the entire string is returned. New_var would inherit the length of the VAR variable if that is the first use. If that isn't desired then use a length statement to set an explicit length.&lt;/P&gt;</description>
      <pubDate>Mon, 12 Jul 2021 17:16:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Translating-a-code-from-SPSS-to-SAS/m-p/753556#M237529</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-07-12T17:16:25Z</dc:date>
    </item>
    <item>
      <title>Re: Translating a code from SPSS to SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Translating-a-code-from-SPSS-to-SAS/m-p/753919#M237686</link>
      <description>&lt;P&gt;Thank you&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/60547"&gt;@sbxkoenk&lt;/a&gt;.&amp;nbsp;Each observation for var is a text and now I know I need to cut the new_var to the portion before the ? mark (only including the text up to the ? mark). Thanks!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 13 Jul 2021 20:22:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Translating-a-code-from-SPSS-to-SAS/m-p/753919#M237686</guid>
      <dc:creator>Emma_at_SAS</dc:creator>
      <dc:date>2021-07-13T20:22:08Z</dc:date>
    </item>
    <item>
      <title>Re: Translating a code from SPSS to SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Translating-a-code-from-SPSS-to-SAS/m-p/753921#M237687</link>
      <description>&lt;P&gt;OK. Fine.&lt;/P&gt;
&lt;P&gt;I guess your question was sufficiently answered by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;and&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;.&lt;/P&gt;
&lt;P&gt;If indeed so, you can mark it as 'solved'.&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;Koen&lt;/P&gt;</description>
      <pubDate>Tue, 13 Jul 2021 20:27:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Translating-a-code-from-SPSS-to-SAS/m-p/753921#M237687</guid>
      <dc:creator>sbxkoenk</dc:creator>
      <dc:date>2021-07-13T20:27:42Z</dc:date>
    </item>
  </channel>
</rss>

