<?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 How to extract a value of variable and create another variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-a-value-of-variable-and-create-another-variable/m-p/621248#M182619</link>
    <description>&lt;P&gt;Dear,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I need help in which function i can in this situation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;my data has values&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;SS-S1 SSS &amp;gt;= 1&amp;nbsp; &amp;nbsp; and SS-S1 SSS&amp;nbsp;&amp;lt; 1.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I need to create another variable with values&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; SSS &amp;gt;= 1 and&amp;nbsp;&amp;nbsp;SSS&amp;nbsp;&amp;lt; 1.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;input data;&lt;/P&gt;
&lt;P&gt;SS-S1 SSS &amp;gt;= 1&lt;/P&gt;
&lt;P&gt;SS-S2 SSS&amp;nbsp;&amp;lt; 1&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;output needed&lt;/P&gt;
&lt;P&gt;SSS &amp;gt;= 1&lt;/P&gt;
&lt;P&gt;SSS&amp;nbsp;&amp;lt; 1&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please suggest. Thank you&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 30 Jan 2020 17:41:23 GMT</pubDate>
    <dc:creator>knveraraju91</dc:creator>
    <dc:date>2020-01-30T17:41:23Z</dc:date>
    <item>
      <title>How to extract a value of variable and create another variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-a-value-of-variable-and-create-another-variable/m-p/621248#M182619</link>
      <description>&lt;P&gt;Dear,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I need help in which function i can in this situation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;my data has values&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;SS-S1 SSS &amp;gt;= 1&amp;nbsp; &amp;nbsp; and SS-S1 SSS&amp;nbsp;&amp;lt; 1.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I need to create another variable with values&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; SSS &amp;gt;= 1 and&amp;nbsp;&amp;nbsp;SSS&amp;nbsp;&amp;lt; 1.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;input data;&lt;/P&gt;
&lt;P&gt;SS-S1 SSS &amp;gt;= 1&lt;/P&gt;
&lt;P&gt;SS-S2 SSS&amp;nbsp;&amp;lt; 1&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;output needed&lt;/P&gt;
&lt;P&gt;SSS &amp;gt;= 1&lt;/P&gt;
&lt;P&gt;SSS&amp;nbsp;&amp;lt; 1&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please suggest. Thank you&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 30 Jan 2020 17:41:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-a-value-of-variable-and-create-another-variable/m-p/621248#M182619</guid>
      <dc:creator>knveraraju91</dc:creator>
      <dc:date>2020-01-30T17:41:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract a value of variable and create another variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-a-value-of-variable-and-create-another-variable/m-p/621260#M182624</link>
      <description>&lt;P&gt;As always, when such small and limited examples are presented, they are hard to generalize.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is the rule that we are supposed to follow that SSS &amp;gt;=1 and SSS &amp;lt; 1 always begin in the 7th column? Or can the SSS &amp;gt;= 1 and SSS &amp;lt; 1 be anywhere in the text string? Do spaces matter — is it always SSS &amp;gt;= 1 or can it be SSS&amp;gt;=1 with no spaces? Does SS-SS1 and SS-SS2 matter at all?&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;What is the rule that you want programmed here?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 30 Jan 2020 18:17:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-a-value-of-variable-and-create-another-variable/m-p/621260#M182624</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-01-30T18:17:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract a value of variable and create another variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-a-value-of-variable-and-create-another-variable/m-p/621278#M182630</link>
      <description>&lt;P&gt;HI&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you for reply. I need second part of the value including spaces. I just need to remove first part of the value '&lt;SPAN&gt;&amp;nbsp;SS-S1&lt;/SPAN&gt;'. Thank you&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Vikram.V&lt;/P&gt;</description>
      <pubDate>Thu, 30 Jan 2020 19:07:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-a-value-of-variable-and-create-another-variable/m-p/621278#M182630</guid>
      <dc:creator>knveraraju91</dc:creator>
      <dc:date>2020-01-30T19:07:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract a value of variable and create another variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-a-value-of-variable-and-create-another-variable/m-p/621283#M182633</link>
      <description>&lt;P&gt;What about when it is SS-S2? Are there other possible values?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You didn't really explain the rule you want programmed ... do we always start in column 7? Or can these codes that you are looking for be anywhere?&lt;/P&gt;</description>
      <pubDate>Thu, 30 Jan 2020 19:19:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-a-value-of-variable-and-create-another-variable/m-p/621283#M182633</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-01-30T19:19:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract a value of variable and create another variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-a-value-of-variable-and-create-another-variable/m-p/621290#M182638</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you very much&lt;/P&gt;
&lt;P&gt;&amp;nbsp;There are only two values for the variable. I need value from column 7. If i use&amp;nbsp; want=substr(a,7);&amp;nbsp; &amp;nbsp;i am getting the output i need.&amp;nbsp; &amp;nbsp;Is there other option. Thank you&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;output needed;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;SSS &amp;gt;= 1&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;SSS &amp;lt; 1&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data one;
input a $1-14 ;
datalines;
SS-S1 SSS &amp;gt;= 1 
SS-S1 SSS &amp;lt; 1  
;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 30 Jan 2020 19:36:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-a-value-of-variable-and-create-another-variable/m-p/621290#M182638</guid>
      <dc:creator>knveraraju91</dc:creator>
      <dc:date>2020-01-30T19:36:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract a value of variable and create another variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-a-value-of-variable-and-create-another-variable/m-p/621299#M182643</link>
      <description>&lt;P&gt;Yes, there are probably other ways to extract a string beginning in column 7, but I would stick with the SUBSTR() function.&lt;/P&gt;</description>
      <pubDate>Thu, 30 Jan 2020 19:55:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-a-value-of-variable-and-create-another-variable/m-p/621299#M182643</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-01-30T19:55:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract a value of variable and create another variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-a-value-of-variable-and-create-another-variable/m-p/621568#M182723</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/68272"&gt;@knveraraju91&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you very much&lt;/P&gt;
&lt;P&gt;&amp;nbsp;There are only two values for the variable. I need value from column 7. If i use&amp;nbsp; want=substr(a,7);&amp;nbsp; &amp;nbsp;i am getting the output i need.&amp;nbsp; &amp;nbsp;Is there other option. Thank you&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;output needed;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;SSS &amp;gt;= 1&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;SSS &amp;lt; 1&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data one;
input a $1-14 ;
datalines;
SS-S1 SSS &amp;gt;= 1 
SS-S1 SSS &amp;lt; 1  
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I agree with &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;that if substr is working for you then that may be best.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This depends on how you are getting the data into SAS in the first place but you may be able to READ that value with an input statement. Actual content and structure of your source may allow use of @"value" column input:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data one;
input @"SS-S1 " a $8. ;
datalines;
SS-S1 SSS &amp;gt;= 1 
SS-S1 SSS &amp;lt; 1  
;&lt;/PRE&gt;
&lt;P&gt;On the input statement an option like &lt;FONT face="SAS Monospace" size="2"&gt;@&lt;/FONT&gt;&lt;FONT color="#800080" face="SAS Monospace" size="2"&gt;"SS-S1 " &lt;/FONT&gt;&lt;FONT color="#000000"&gt;tells SAS to advance the read point to the column after the end of the value in quotes and then read the variable. &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000000"&gt;Concerns: The entire structure of the data and options use. If you are using list input then you need something that reads the spaces if the delimiter is not something other than that a space if the data is delimited. The approach I show will include any character immediately after the 1 in the "SSS&amp;nbsp;&amp;lt; 1" case because we are forcing a read of 8 characters. &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000000"&gt;Another approach could be to use a custom Informat that would read &lt;/FONT&gt;SS-S1 SSS &amp;gt;= 1 into a value of "SSS &amp;gt;= 1". But again we have to either know the file contents when read or use a more complex method than substring:&lt;/P&gt;
&lt;PRE&gt;proc format library=work;
invalue $sss
"SS-S1 SSS &amp;gt;= 1" = "SSS &amp;gt;= 1"
"SS-S1 SSS &amp;lt; 1"  = "SSS &amp;lt; 1"
;

data one;
input a $1-14 ;
datalines;
SS-S1 SSS &amp;gt;= 1 
SS-S1 SSS &amp;lt; 1  
;

data two;
   set one;
   newvar = input(a,$sss.);
run;&lt;/PRE&gt;
&lt;P&gt;This approach might be preferred over SUBSTR if you have many values that need many different places to parse from.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or just create a format and use the format without actually changing the value. This of course depends on what you are doing with the variable. If it is used for grouping in reports, analysis or graphs that should suffice.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc format library=work;
value $sss
"SS-S1 SSS &amp;gt;= 1" = "SSS &amp;gt;= 1"
"SS-S1 SSS &amp;lt; 1"  = "SSS &amp;lt; 1"
;
run;

proc print data=one;
   format a $sss.;
run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 31 Jan 2020 22:43:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-a-value-of-variable-and-create-another-variable/m-p/621568#M182723</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-01-31T22:43:24Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract a value of variable and create another variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-a-value-of-variable-and-create-another-variable/m-p/621802#M182851</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/68272"&gt;@knveraraju91&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you very much&lt;/P&gt;
&lt;P&gt;&amp;nbsp;There are only two values for the variable. I need value from column 7. If i use&amp;nbsp; want=substr(a,7);&amp;nbsp; &amp;nbsp;i am getting the output i need.&amp;nbsp; &amp;nbsp;Is there other option. Thank you&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;output needed;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;SSS &amp;gt;= 1&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;SSS &amp;lt; 1&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data one;
input a $1-14 ;
datalines;
SS-S1 SSS &amp;gt;= 1 
SS-S1 SSS &amp;lt; 1  
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I agree with &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;that if substr is working for you then that may be best.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This depends on how you are getting the data into SAS in the first place but you may be able to READ that value with an input statement. Actual content and structure of your source may allow use of @"value" column input:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data one;
input @"SS-S1 " a $8. ;
datalines;
SS-S1 SSS &amp;gt;= 1 
SS-S1 SSS &amp;lt; 1  
;&lt;/PRE&gt;
&lt;P&gt;On the input statement an option like &lt;FONT size="2" face="SAS Monospace"&gt;@&lt;/FONT&gt;&lt;FONT size="2" face="SAS Monospace" color="#800080"&gt;"SS-S1 " &lt;/FONT&gt;&lt;FONT color="#000000"&gt;tells SAS to advance the read point to the column after the end of the value in quotes and then read the variable. &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Problem: the original data set contained SS-S1 and SS-S2&lt;/P&gt;</description>
      <pubDate>Sun, 02 Feb 2020 19:11:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-a-value-of-variable-and-create-another-variable/m-p/621802#M182851</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-02-02T19:11:15Z</dc:date>
    </item>
  </channel>
</rss>

