<?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: to create new variables from exsting variable which is delimited in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/to-create-new-variables-from-exsting-variable-which-is-delimited/m-p/266539#M52553</link>
    <description>&lt;P&gt;It looks like you're parsing web queries in some form? Or an HTML address?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 26 Apr 2016 20:46:07 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2016-04-26T20:46:07Z</dc:date>
    <item>
      <title>to create new variables from exsting variable which is delimited</title>
      <link>https://communities.sas.com/t5/SAS-Programming/to-create-new-variables-from-exsting-variable-which-is-delimited/m-p/266460#M52528</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Need suggestion on creating new variables from an existing variable which is delimited.&lt;/P&gt;&lt;P&gt;foir example i have values in the variable VAR_A as&lt;/P&gt;&lt;P&gt;&amp;amp;PRODUCT=AXCV12345&amp;amp;sState=ABC&amp;amp;year_det=2014&amp;amp;TELEPH=1234567890.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i need to create new variables from variable "VAR_A".&lt;/P&gt;&lt;P&gt;product&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; State&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; year_det&amp;nbsp;&amp;nbsp; Phone_Number&lt;/P&gt;&lt;P&gt;AXCV12345&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ABC&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2014&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1234567890&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;the delimiter appears "&amp;amp;,? and =" appear more than once for the variable&amp;nbsp; "VAR_A".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please suggest.&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>Tue, 26 Apr 2016 17:22:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/to-create-new-variables-from-exsting-variable-which-is-delimited/m-p/266460#M52528</guid>
      <dc:creator>santosh_pat69</dc:creator>
      <dc:date>2016-04-26T17:22:32Z</dc:date>
    </item>
    <item>
      <title>Re: to create new variables from exsting variable which is delimited</title>
      <link>https://communities.sas.com/t5/SAS-Programming/to-create-new-variables-from-exsting-variable-which-is-delimited/m-p/266462#M52529</link>
      <description>&lt;P&gt;Here are some questions to consider, before the programming begins.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How do you know which variables are character and which are numeric?&amp;nbsp; For example, Phone Number would normally be stored as character even if it contains only digits.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Should each observation in the data set execute only the VAR_A instructions that appear on that observation?&amp;nbsp; Or does the contents of VAR_A apply to all observations in the data set?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Could variables have different lengths for different values of VAR_A?&amp;nbsp; For example, could one observation contain &amp;amp;STATE=Utah&amp;amp; while another contains &amp;amp;STATE=Minnesota&amp;amp; and another contains &amp;amp;STATE=New York&amp;amp; ?&amp;nbsp; Do you know what the longest required length would be for each possible character variable referenced within VAR_A?&lt;/P&gt;</description>
      <pubDate>Tue, 26 Apr 2016 17:33:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/to-create-new-variables-from-exsting-variable-which-is-delimited/m-p/266462#M52529</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-04-26T17:33:44Z</dc:date>
    </item>
    <item>
      <title>Re: to create new variables from exsting variable which is delimited</title>
      <link>https://communities.sas.com/t5/SAS-Programming/to-create-new-variables-from-exsting-variable-which-is-delimited/m-p/266463#M52530</link>
      <description>&lt;P&gt;Do the variables ALWAYS appear in the same order and ALWAYS appear in each record?&lt;/P&gt;
&lt;P&gt;If so in a data step you could use:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
    set have;
    /* it is a good idea to set Lengths for the results before use
       long enough to hold the longest expected value*/
    Length Product $ 
    Product = scan(Var_A,2,'&amp;amp;=?');
    State = scan(Var_A,4,'&amp;amp;=?');
    Year_det = input(scan(Var_A,6,'&amp;amp;=?'),best.); /* assumes you want this as numeric value*/
    Phone_number = scan(Var_A,8,'&amp;amp;=?');
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note that since you don't show use of ? then there could be different behavior.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;IF the order may change or some variables could be missing this won't work and you'll have to do some searching of in the variable using FIND or index functions.&lt;/P&gt;</description>
      <pubDate>Tue, 26 Apr 2016 17:38:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/to-create-new-variables-from-exsting-variable-which-is-delimited/m-p/266463#M52530</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-04-26T17:38:00Z</dc:date>
    </item>
    <item>
      <title>Re: to create new variables from exsting variable which is delimited</title>
      <link>https://communities.sas.com/t5/SAS-Programming/to-create-new-variables-from-exsting-variable-which-is-delimited/m-p/266466#M52532</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;Thank you for looking into this and posting your vluable comments.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How do you know which variables are character and which are numeric?&amp;nbsp; For example, Phone Number would normally be stored as character even if it contains only digits.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The variables stored as character.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Should each observation in the data set execute only the VAR_A instructions that appear on that observation?&amp;nbsp; Or does the contents of VAR_A apply to all observations in the data set?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;VAR_A apply to all observations in the data set.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Could variables have different lengths for different values of VAR_A?&amp;nbsp; For example, could one observation contain &amp;amp;STATE=Utah&amp;amp; while another contains &amp;amp;STATE=Minnesota&amp;amp; and another contains &amp;amp;STATE=New York&amp;amp; ?&amp;nbsp; Do you know what the longest required length would be for each possible character variable referenced within VAR_A?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Yes it can have multiple lengths, i am not sure of the longest length as the&lt;/P&gt;&lt;P&gt;VAR_A looks something like this&lt;/P&gt;&lt;P&gt;&amp;amp;STATE=Minnesota&amp;amp;PRODUCT=AAAXXXCCC&amp;amp;TELEPHONE=1234567890.&lt;/P&gt;&lt;P&gt;so i have defined length of A as 250.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Apr 2016 17:42:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/to-create-new-variables-from-exsting-variable-which-is-delimited/m-p/266466#M52532</guid>
      <dc:creator>santosh_pat69</dc:creator>
      <dc:date>2016-04-26T17:42:01Z</dc:date>
    </item>
    <item>
      <title>Re: to create new variables from exsting variable which is delimited</title>
      <link>https://communities.sas.com/t5/SAS-Programming/to-create-new-variables-from-exsting-variable-which-is-delimited/m-p/266472#M52533</link>
      <description>&lt;P&gt;Hi Super user,&lt;/P&gt;&lt;P&gt;Thank you for your comments and suggestions.&lt;/P&gt;&lt;P&gt;FIND or index need to be used, i was looking for a function which search the position of "&amp;amp;=,?" and read it into a macro variable and then use the macro variable in a Do loop other than creating the other variables based on the position of the &amp;amp; = , ?.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Kindly suggest&lt;/P&gt;</description>
      <pubDate>Tue, 26 Apr 2016 17:51:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/to-create-new-variables-from-exsting-variable-which-is-delimited/m-p/266472#M52533</guid>
      <dc:creator>santosh_pat69</dc:creator>
      <dc:date>2016-04-26T17:51:19Z</dc:date>
    </item>
    <item>
      <title>Re: to create new variables from exsting variable which is delimited</title>
      <link>https://communities.sas.com/t5/SAS-Programming/to-create-new-variables-from-exsting-variable-which-is-delimited/m-p/266511#M52542</link>
      <description>&lt;P&gt;There is absolutely no need for a macro for this.&lt;/P&gt;
&lt;P&gt;If the order changes then you have one piece of code to look for each variable that you know of.&lt;/P&gt;
&lt;P&gt;This shows one example. I did not assign a length for the variable(s) and hence this example gets the length of the starting X variable.&lt;/P&gt;
&lt;P&gt;For your year again use the Input bit for a numeric.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data example;
   x='&amp;amp;PRODUCT=AXCV12345&amp;amp;sState=ABC&amp;amp;year_det=2014&amp;amp;TELEPH​=1234567890';
   /* how to find your product variable if the order changes, or may not be there*/
   /* check to see if the variable is there*/
   pos = index(x,'PRODUCT=');
   if pos&amp;gt;0 then do;  /* the variable is there if not in the string this bit is skipped*/
      /*POS has the position of the string, so you know the the value you want starts at POS+length of variable and the =,8 in this case*/
      /* so you search from that to find the &amp;amp; which appears to be the end of the value*/
      endpos = find(x,'&amp;amp;',Pos);
      Product = substr(x,Pos+8,endpos-(Pos+8));
   end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;You still have not shown how the ? might appear&lt;/STRONG&gt;.&lt;/P&gt;</description>
      <pubDate>Tue, 26 Apr 2016 19:46:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/to-create-new-variables-from-exsting-variable-which-is-delimited/m-p/266511#M52542</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-04-26T19:46:06Z</dc:date>
    </item>
    <item>
      <title>Re: to create new variables from exsting variable which is delimited</title>
      <link>https://communities.sas.com/t5/SAS-Programming/to-create-new-variables-from-exsting-variable-which-is-delimited/m-p/266539#M52553</link>
      <description>&lt;P&gt;It looks like you're parsing web queries in some form? Or an HTML address?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Apr 2016 20:46:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/to-create-new-variables-from-exsting-variable-which-is-delimited/m-p/266539#M52553</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-04-26T20:46:07Z</dc:date>
    </item>
    <item>
      <title>Re: to create new variables from exsting variable which is delimited</title>
      <link>https://communities.sas.com/t5/SAS-Programming/to-create-new-variables-from-exsting-variable-which-is-delimited/m-p/266563#M52564</link>
      <description>&lt;P&gt;Hi Super User,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you so much!!!!&lt;/P&gt;&lt;P&gt;Your comments and suggestions helped me alot to achieve.&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;&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>Tue, 26 Apr 2016 22:15:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/to-create-new-variables-from-exsting-variable-which-is-delimited/m-p/266563#M52564</guid>
      <dc:creator>santosh_pat69</dc:creator>
      <dc:date>2016-04-26T22:15:21Z</dc:date>
    </item>
    <item>
      <title>Re: to create new variables from exsting variable which is delimited</title>
      <link>https://communities.sas.com/t5/SAS-Programming/to-create-new-variables-from-exsting-variable-which-is-delimited/m-p/266566#M52566</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/38367"&gt;@santosh_pat69﻿&lt;/a&gt;&amp;nbsp;if your issue is resolved please take the time to mark the appropriate response as the correc answer.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Apr 2016 22:21:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/to-create-new-variables-from-exsting-variable-which-is-delimited/m-p/266566#M52566</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-04-26T22:21:20Z</dc:date>
    </item>
  </channel>
</rss>

