<?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: Char to numeric and aggregate in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Char-to-numeric-and-aggregate/m-p/753698#M237596</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/181158"&gt;@tarheel13&lt;/a&gt;&amp;nbsp;data which you have in your program is correct. Without group by we won't be getting the desired results.&lt;/P&gt;</description>
    <pubDate>Tue, 13 Jul 2021 07:45:50 GMT</pubDate>
    <dc:creator>David_Billa</dc:creator>
    <dc:date>2021-07-13T07:45:50Z</dc:date>
    <item>
      <title>Char to numeric and aggregate</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Char-to-numeric-and-aggregate/m-p/753665#M237576</link>
      <description>&lt;P&gt;I'm trying to find the maximum value from VALUE field group by on two fields (Id, CRF)&amp;nbsp;as shown below. I'd would like to understand whether this program is logically correct. I'm not getting the desired results with this program. I don't wish to create a any new field after converting the VALUE from character to numeric.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Input Data:&lt;/P&gt;
&lt;PRE&gt;Id	        CRF	         Value
PLAP24MRT_MV	[INS]#MAX1	-956461.285475
PLAP24MRT_MV	[INS]#MAX2	-30254.271916
&lt;/PRE&gt;
&lt;P&gt;Desired Result:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;Id	        CRF	 Value
PLAP24MRT_MV	[INS]	-30254.271916
&lt;/PRE&gt;
&lt;P&gt;Program:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc Sql;
    create table Want as select distinct * from (
        select Id
               ,scan(CRF,1,'#') as CRF, (
            case 
                when scan(CRF,-1,,'ka')="MIN" then strip(put(min(input(Value,24.6)),24.6))
                when scan(CRF,-1,,'ka')="MAX" then strip(put(max(input(Value,24.6)),24.6))
                when scan(CRF,-1,,'ka')="AVG" then strip(put(avg(input(Value,24.6)),24.6))
                when scan(CRF,-1,,'ka')="STD" then strip(put(std(input(Value,24.6)),24.6))
                else ''
            end )
        as Value
        from INPUT
        group by Id,CRF);
quit;&lt;/PRE&gt;</description>
      <pubDate>Tue, 13 Jul 2021 06:24:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Char-to-numeric-and-aggregate/m-p/753665#M237576</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2021-07-13T06:24:50Z</dc:date>
    </item>
    <item>
      <title>Re: Char to numeric and aggregate</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Char-to-numeric-and-aggregate/m-p/753667#M237577</link>
      <description>&lt;P&gt;Make a small set of data where you know what the result should be. You should include some of those CRF values with "min","avg" and "std" to properly test your code.&lt;/P&gt;
&lt;P&gt;Run your code.&lt;/P&gt;
&lt;P&gt;Does it match your expectation?.&lt;/P&gt;</description>
      <pubDate>Tue, 13 Jul 2021 06:35:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Char-to-numeric-and-aggregate/m-p/753667#M237577</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-07-13T06:35:41Z</dc:date>
    </item>
    <item>
      <title>Re: Char to numeric and aggregate</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Char-to-numeric-and-aggregate/m-p/753669#M237579</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;Tried already. It's not producing the desired results. May I know whether the charcter to numeric and then to character conversion is correct in CASE WHEN as shown in initial post?&lt;/P&gt;</description>
      <pubDate>Tue, 13 Jul 2021 06:43:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Char-to-numeric-and-aggregate/m-p/753669#M237579</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2021-07-13T06:43:08Z</dc:date>
    </item>
    <item>
      <title>Re: Char to numeric and aggregate</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Char-to-numeric-and-aggregate/m-p/753673#M237581</link>
      <description>&lt;P&gt;I don't use subqueries in Case statements but to select a maximum value by group I would expect to see something like&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;Proc sql;
   create table want as
   select &amp;lt;group vars&amp;gt;, max(numeric expression)
   from dataset
   group by &amp;lt;group vars&amp;gt;
   ;
quit;

&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you only want to consider values where CRF contains MAX that would be a WHERE subsetting the data set such as:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;Proc sql;
   create table want as
   select &amp;lt;group vars&amp;gt;, Put(max(numeric expression),24.6) as value
   from (select * from  dataset where scan(CRF,-1,,'ka')='MAX'  )
   group by &amp;lt;group vars&amp;gt;
   ;
quit;&lt;/PRE&gt;
&lt;P&gt;Or similar. &lt;BR /&gt;You want to test what your INPUT is creating. You may find that if you have integers the value is not as expected.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Consider:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data example; 
   x="-956461";
   y=input(x,24.6);
run;&lt;/PRE&gt;
&lt;P&gt;Look very closely for a decimal in the above.&amp;nbsp; Leading spaces might make things even more entertaining. Input unless you are dealing with fixed implicit decimal places is typically not desired. An F24. informat (or 24.0) will read the numeric values just fine.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Of course one does wonder why a value like character to begin with.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As always, actual example data in the form of a data step might get something that works quicker.&lt;/P&gt;
&lt;P&gt;Since your "example" of two lines had none of "avg" "min" or "std" it is real hard for us to test any code.&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, 13 Jul 2021 07:10:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Char-to-numeric-and-aggregate/m-p/753673#M237581</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-07-13T07:10:04Z</dc:date>
    </item>
    <item>
      <title>Re: Char to numeric and aggregate</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Char-to-numeric-and-aggregate/m-p/753676#M237583</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
	create table have 
	(id char(200),CRF char(200), value char(200));
	insert into have 
	values('PLAP24MRT_MV','[INS]#MAX1','-956461.285475')
	values('PLAP24MRT_MV', '[INS]#MAX2','-30254.271916');	
quit;

data have2;
	set have;
	new_CRF=scan(CRF,1,'#');
	val=input(value,24.6);
run;

proc sql;
	create table have3 as
	select distinct id, new_CRF,
	case when scan(CRF,-1,,'ka')="MIN" then strip(put(min(val),26.4))
    when scan(CRF,-1,,'ka')="MAX" then strip(put(max(val),26.4))
    when scan(CRF,-1,,'ka')="AVG" then strip(put(mean(val),26.4))
    when scan(CRF,-1,,'ka')="STD" then strip(put(std(val),26.4))
    else '' end as value
    	from have2
    	group by id, new_CRF;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I don't see the issue? This gets -30254.271916 as the result.&lt;/P&gt;</description>
      <pubDate>Tue, 13 Jul 2021 07:13:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Char-to-numeric-and-aggregate/m-p/753676#M237583</guid>
      <dc:creator>tarheel13</dc:creator>
      <dc:date>2021-07-13T07:13:26Z</dc:date>
    </item>
    <item>
      <title>Re: Char to numeric and aggregate</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Char-to-numeric-and-aggregate/m-p/753678#M237584</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/181158"&gt;@tarheel13&lt;/a&gt;&amp;nbsp;can we do this in two steps by removing have2 datastep?&amp;nbsp; Also may I know why you're changing the format to 26.4? Can't we retain with 24.6?&lt;/P&gt;</description>
      <pubDate>Tue, 13 Jul 2021 07:18:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Char-to-numeric-and-aggregate/m-p/753678#M237584</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2021-07-13T07:18:21Z</dc:date>
    </item>
    <item>
      <title>Re: Char to numeric and aggregate</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Char-to-numeric-and-aggregate/m-p/753682#M237586</link>
      <description>&lt;P&gt;The 24.6 was a mistake. But anyway I agree with&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;and I don't think you need to use subqueries either. You can put it in one SQL and remove the DATA step. The result is still the same.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
	create table have3 as
	select distinct id, scan(CRF,1,'#') as CRF,
	case when scan(CRF,-1,,'ka')="MIN" then strip(put(min(input(value,26.4)),26.4))
    when scan(CRF,-1,,'ka')="MAX" then strip(put(max(input(value,26.4)),26.4))
    when scan(CRF,-1,,'ka')="AVG" then strip(put(mean(input(value,26.4)),26.4))
    when scan(CRF,-1,,'ka')="STD" then strip(put(std(input(value,26.4)),26.4))
    else '' end as value
    	from have2
    	group by id, CRF;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 13 Jul 2021 07:24:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Char-to-numeric-and-aggregate/m-p/753682#M237586</guid>
      <dc:creator>tarheel13</dc:creator>
      <dc:date>2021-07-13T07:24:13Z</dc:date>
    </item>
    <item>
      <title>Re: Char to numeric and aggregate</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Char-to-numeric-and-aggregate/m-p/753684#M237587</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/292396"&gt;@David_Billa&lt;/a&gt;&amp;nbsp;Getting sample data in the form of a data step with at least two cases wouldn't have hurt.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Does below give you what you're after? I was actually surprised that the functions really only execute on aggregate level during group by processing and not just on row level - but it appears to work.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input (Id CRF) (:$20.) Value :$20.;
  datalines;
PLAP24MRT_MV [INS]#MAX1 -956461.285475
PLAP24MRT_MV [INS]#MAX2 -30254.271916
PLAP24MRT_MV [INS]#MIN1 -956461.285475
PLAP24MRT_MV [INS]#MIN2 -30254.271916
;

proc Sql;
  create view v_inter as
    select 
      id,
      scan(CRF,1,'#') as CRF length=10,
      scan(CRF,-1,,'ka') as function length=3,
      input(Value,32.) as value format=24.6
    from have
    ; 
  create table Want as 
    select distinct
      Id,
      CRF, 
      function,
      case function 
        when "MIN" then min(Value)
        when "MAX" then max(Value)
        when "AVG" then avg(Value)
        when "STD" then std(Value)
        else missing(value)
      end 
      as Value format=24.6
    from v_inter
    group by Id,CRF,Function
  ;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_0-1626160799924.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/61154iF6125BB07857656F/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Patrick_0-1626160799924.png" alt="Patrick_0-1626160799924.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Also important:&lt;/P&gt;
&lt;P&gt;Do &lt;STRONG&gt;NOT&lt;/STRONG&gt; use an informat with a decimal portion unless you know exactly what you're doing.&lt;/P&gt;
&lt;P&gt;IF your source string doesn't have a decimal portion then SAS will assume the should be one and divide the number by 10 power decimal portion.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data demo;
  input Value 24.6;
  format value 24.6;
  datalines;
-956461.285475
-956461.
-956461
;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_1-1626161061488.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/61155iEF77E6D60EA639E9/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Patrick_1-1626161061488.png" alt="Patrick_1-1626161061488.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 13 Jul 2021 07:35:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Char-to-numeric-and-aggregate/m-p/753684#M237587</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2021-07-13T07:35:45Z</dc:date>
    </item>
    <item>
      <title>Re: Char to numeric and aggregate</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Char-to-numeric-and-aggregate/m-p/753687#M237589</link>
      <description>&lt;P&gt;Also don't think the group by is necessary but again you have not posted your data so it is hard to tell you.&lt;/P&gt;</description>
      <pubDate>Tue, 13 Jul 2021 07:29:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Char-to-numeric-and-aggregate/m-p/753687#M237589</guid>
      <dc:creator>tarheel13</dc:creator>
      <dc:date>2021-07-13T07:29:46Z</dc:date>
    </item>
    <item>
      <title>Re: Char to numeric and aggregate</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Char-to-numeric-and-aggregate/m-p/753689#M237590</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;&amp;nbsp;thank you. I want the solution in one step instead of two steps. Also I want the&amp;nbsp;VALUE field to be character in the result.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 13 Jul 2021 07:32:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Char-to-numeric-and-aggregate/m-p/753689#M237590</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2021-07-13T07:32:27Z</dc:date>
    </item>
    <item>
      <title>Re: Char to numeric and aggregate</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Char-to-numeric-and-aggregate/m-p/753692#M237592</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/181158"&gt;@tarheel13&lt;/a&gt;&amp;nbsp;It's not producing the desired results. You can execute and check&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc sql;
create table have 
	(id char(200),CRF char(200), value char(200));
	insert into have 
	values('PLAP24MRT_MV','[INS]#MAX1','-956461.285475')
	values('PLAP24MRT_MV', '[INS]#MAX2','-30254.271916');	
quit;


proc sql;
	create table have3 as
	select distinct id, scan(CRF,1,'#') as CRF,
	case when scan(CRF,-1,,'ka')="MIN" then strip(put(min(input(value,26.4)),26.4))
    when scan(CRF,-1,,'ka')="MAX" then strip(put(max(input(value,26.4)),26.4))
    when scan(CRF,-1,,'ka')="AVG" then strip(put(mean(input(value,26.4)),26.4))
    when scan(CRF,-1,,'ka')="STD" then strip(put(std(input(value,26.4)),26.4))
    else '' end as value
    	from have
    	group by id, CRF;
quit;&lt;/PRE&gt;</description>
      <pubDate>Tue, 13 Jul 2021 07:37:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Char-to-numeric-and-aggregate/m-p/753692#M237592</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2021-07-13T07:37:54Z</dc:date>
    </item>
    <item>
      <title>Re: Char to numeric and aggregate</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Char-to-numeric-and-aggregate/m-p/753695#M237594</link>
      <description>&lt;P&gt;I also told you to remove the group by. Or else do what&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;&amp;nbsp;did and include the function in the group by clause.&lt;/P&gt;</description>
      <pubDate>Tue, 13 Jul 2021 07:39:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Char-to-numeric-and-aggregate/m-p/753695#M237594</guid>
      <dc:creator>tarheel13</dc:creator>
      <dc:date>2021-07-13T07:39:58Z</dc:date>
    </item>
    <item>
      <title>Re: Char to numeric and aggregate</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Char-to-numeric-and-aggregate/m-p/753697#M237595</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/292396"&gt;@David_Billa&lt;/a&gt;&amp;nbsp;Below how you get value as a string in the result.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Using a view which only executes when called in the 2nd SQL allows imho for code that's easier to read and maintain. From a processing perspective things only execute in the 2nd SQL.&lt;/P&gt;
&lt;P&gt;It wouldn't be that hard to move all the logic from the view into the 2nd SQL - but I'm not going to do this as it's just ugly without adding benefit.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc Sql;
  create view v_inter as
    select 
      id,
      scan(CRF,1,'#') as CRF length=10,
      scan(CRF,-1,,'ka') as function length=3,
      input(Value,32.) as value format=24.6
    from have
    ; 
  create table Want as 
    select distinct
      Id,
      CRF, 
      function,
      put(
          case function 
            when "MIN" then min(Value)
            when "MAX" then max(Value)
            when "AVG" then avg(Value)
            when "STD" then std(Value)
            else missing(value)
          end 
          , 24.6 -l)
        as Value 
    from v_inter
    group by Id,CRF,Function
  ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 13 Jul 2021 07:44:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Char-to-numeric-and-aggregate/m-p/753697#M237595</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2021-07-13T07:44:32Z</dc:date>
    </item>
    <item>
      <title>Re: Char to numeric and aggregate</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Char-to-numeric-and-aggregate/m-p/753698#M237596</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/181158"&gt;@tarheel13&lt;/a&gt;&amp;nbsp;data which you have in your program is correct. Without group by we won't be getting the desired results.&lt;/P&gt;</description>
      <pubDate>Tue, 13 Jul 2021 07:45:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Char-to-numeric-and-aggregate/m-p/753698#M237596</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2021-07-13T07:45:50Z</dc:date>
    </item>
    <item>
      <title>Re: Char to numeric and aggregate</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Char-to-numeric-and-aggregate/m-p/753699#M237597</link>
      <description>Okay, I am leaving this conversation. The group by also does not get what you want.</description>
      <pubDate>Tue, 13 Jul 2021 07:47:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Char-to-numeric-and-aggregate/m-p/753699#M237597</guid>
      <dc:creator>tarheel13</dc:creator>
      <dc:date>2021-07-13T07:47:30Z</dc:date>
    </item>
    <item>
      <title>Re: Char to numeric and aggregate</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Char-to-numeric-and-aggregate/m-p/753700#M237598</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;&amp;nbsp;Please clarify why you've added function in your program.&lt;/P&gt;</description>
      <pubDate>Tue, 13 Jul 2021 07:56:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Char-to-numeric-and-aggregate/m-p/753700#M237598</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2021-07-13T07:56:32Z</dc:date>
    </item>
    <item>
      <title>Re: Char to numeric and aggregate</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Char-to-numeric-and-aggregate/m-p/753702#M237600</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/292396"&gt;@David_Billa&lt;/a&gt;&amp;nbsp;Because based on the sample data and code you've posted I've made the assumption that for the same ID there could be data as I've created in my post. So for same ID a value for CRF that could always contain a sub-string [INS] but then different function names in the remaining string. If so then you would likely want to aggregate on the lowest level of the function given the code you shared.&lt;/P&gt;</description>
      <pubDate>Tue, 13 Jul 2021 08:02:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Char-to-numeric-and-aggregate/m-p/753702#M237600</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2021-07-13T08:02:14Z</dc:date>
    </item>
    <item>
      <title>Re: Char to numeric and aggregate</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Char-to-numeric-and-aggregate/m-p/753703#M237601</link>
      <description>&lt;P&gt;One last question. Can't we achieve it without creating function? Also what is the meaning of &lt;STRONG&gt;-l&lt;/STRONG&gt; in PUT function?&lt;/P&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 13 Jul 2021 08:05:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Char-to-numeric-and-aggregate/m-p/753703#M237601</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2021-07-13T08:05:20Z</dc:date>
    </item>
    <item>
      <title>Re: Char to numeric and aggregate</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Char-to-numeric-and-aggregate/m-p/753707#M237603</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/292396"&gt;@David_Billa&lt;/a&gt;&amp;nbsp;The -l stands for LeftAligned. Without it the string in value would be right aligned with leading blanks which is something people normally don't want.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Yes. with SAS SQL you could also not use variable Function in the group by clause and it would still work. SAS somehow internally still creates groups per aggregate function. But then: The aggregation is on function level so this is just about clean code that someone else can understand and maintain (and you still can understand in one year's time).&lt;/P&gt;</description>
      <pubDate>Tue, 13 Jul 2021 08:17:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Char-to-numeric-and-aggregate/m-p/753707#M237603</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2021-07-13T08:17:25Z</dc:date>
    </item>
    <item>
      <title>Re: Char to numeric and aggregate</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Char-to-numeric-and-aggregate/m-p/753796#M237643</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/292396"&gt;@David_Billa&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;One last question. Can't we achieve it without creating function? Also what is the meaning of &lt;STRONG&gt;-l&lt;/STRONG&gt; in PUT function?&lt;/P&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;The -L (to make it more legible) in Put means to left justify the result. By default Put with a numeric format will right justify the value and if the value does not "fill" the format there will be leading zeroes.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;PRE&gt;data example;
    x=3;
    y= quote(put(x,f12.2));
    z= quote(put(x,f12.2 -L));
run;&lt;/PRE&gt;
&lt;P&gt;The Quote places quote marks around the value so you can see just how the value has resolved with the Put function.&lt;/P&gt;
&lt;P&gt;The presence of leading spaces can lead to all sorts of interesting behaviors depending what you do with a value like that later. Some are apparent "duplicate" values that are treated as different, failure to convert back to numeric with INPUT, unexpected spaces in concatenation operations and unexpected "sort" order results.&lt;/P&gt;</description>
      <pubDate>Tue, 13 Jul 2021 15:25:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Char-to-numeric-and-aggregate/m-p/753796#M237643</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-07-13T15:25:35Z</dc:date>
    </item>
  </channel>
</rss>

