<?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 use different weights on the same variable without intermediate datasteps or using proc sql? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-different-weights-on-the-same-variable-without/m-p/801132#M315271</link>
    <description>&lt;P&gt;I can't find a way to summarize the same variable using different weights.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I try to explain it with an example (of 3 records):&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;data pippo;
    a=10;  
    wgt1=0.5;  
    wgt2=1;  
    wgt3=0;
    output;
    a=3;  
    wgt1=0;  
    wgt2=0;  
    wgt3=1;
    output;
    a=8.9;  
    wgt1=1.2;  
    wgt2=0.3;  
    wgt3=0.1;
    output;
run; &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I tried the following:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;proc summary data=pippo missing nway;  
      var a /weight=wgt1;  
      var a /weight=wgt2;  
      var a /weight=wgt3;  
output out=pluto (drop=_freq_ _type_) sum()=;  
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Obviously it gives me a warning because I used the same variable "a" (I can't rename it!).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I can do it but just for one variable:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;proc summary data=pippo missing nway;  
      var wgt1-wgt3 /weight=a;  
output out=pluto (drop=_freq_ _type_) sum(wgt1-wgt3)=a1-a3;  
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;But if I introduce a second variable I can't use that trick&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;proc summary data=pippo missing nway;  
      var wgt1-wgt3 /weight=a;&lt;BR /&gt;      var wgt1-wgt3 /weight=b; &amp;lt;---- WRONG!!! 
output out=pluto (drop=_freq_ _type_) &lt;BR /&gt;      sum(wgt1-wgt3)=a1-a3&lt;BR /&gt;      sum(wgt1-wgt3)=b1-b3;&amp;lt;---SAME NAME, WRONG!!!
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I've to save a huge amount of data, I've not so much physical space and I should construct like 120 field (a0-a6,b0-b6 etc) that are the same variables just with fixed weight (wgt0-wgt5).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to store a dataset with 20 columns (a,b,c..) and 6 weight (wgt0-wgt5) and, on demand, processing a "summary" without an intermediate datastep that oblige me to create 120 fields.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Due to the huge amount of data I'd like also not to use proc sql statement (even because I've to write it manually for each variable):&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;proc sql;  
create table pluto  
as select sum(db.a * wgt1) as a1, sum(db.a * wgt2) as a2 , etc.  
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Is There a "Super proc summary" that can summarize the same field with different weights?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance,&lt;BR /&gt;Paolo&lt;/P&gt;</description>
    <pubDate>Wed, 09 Mar 2022 16:44:07 GMT</pubDate>
    <dc:creator>Paolo_1981</dc:creator>
    <dc:date>2022-03-09T16:44:07Z</dc:date>
    <item>
      <title>How to use different weights on the same variable without intermediate datasteps or using proc sql?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-different-weights-on-the-same-variable-without/m-p/801132#M315271</link>
      <description>&lt;P&gt;I can't find a way to summarize the same variable using different weights.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I try to explain it with an example (of 3 records):&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;data pippo;
    a=10;  
    wgt1=0.5;  
    wgt2=1;  
    wgt3=0;
    output;
    a=3;  
    wgt1=0;  
    wgt2=0;  
    wgt3=1;
    output;
    a=8.9;  
    wgt1=1.2;  
    wgt2=0.3;  
    wgt3=0.1;
    output;
run; &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I tried the following:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;proc summary data=pippo missing nway;  
      var a /weight=wgt1;  
      var a /weight=wgt2;  
      var a /weight=wgt3;  
output out=pluto (drop=_freq_ _type_) sum()=;  
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Obviously it gives me a warning because I used the same variable "a" (I can't rename it!).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I can do it but just for one variable:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;proc summary data=pippo missing nway;  
      var wgt1-wgt3 /weight=a;  
output out=pluto (drop=_freq_ _type_) sum(wgt1-wgt3)=a1-a3;  
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;But if I introduce a second variable I can't use that trick&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;proc summary data=pippo missing nway;  
      var wgt1-wgt3 /weight=a;&lt;BR /&gt;      var wgt1-wgt3 /weight=b; &amp;lt;---- WRONG!!! 
output out=pluto (drop=_freq_ _type_) &lt;BR /&gt;      sum(wgt1-wgt3)=a1-a3&lt;BR /&gt;      sum(wgt1-wgt3)=b1-b3;&amp;lt;---SAME NAME, WRONG!!!
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I've to save a huge amount of data, I've not so much physical space and I should construct like 120 field (a0-a6,b0-b6 etc) that are the same variables just with fixed weight (wgt0-wgt5).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to store a dataset with 20 columns (a,b,c..) and 6 weight (wgt0-wgt5) and, on demand, processing a "summary" without an intermediate datastep that oblige me to create 120 fields.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Due to the huge amount of data I'd like also not to use proc sql statement (even because I've to write it manually for each variable):&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;proc sql;  
create table pluto  
as select sum(db.a * wgt1) as a1, sum(db.a * wgt2) as a2 , etc.  
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Is There a "Super proc summary" that can summarize the same field with different weights?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance,&lt;BR /&gt;Paolo&lt;/P&gt;</description>
      <pubDate>Wed, 09 Mar 2022 16:44:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-different-weights-on-the-same-variable-without/m-p/801132#M315271</guid>
      <dc:creator>Paolo_1981</dc:creator>
      <dc:date>2022-03-09T16:44:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to use different weights on the same variable without intermediate datasteps or using proc s</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-different-weights-on-the-same-variable-without/m-p/801199#M315298</link>
      <description>&lt;P&gt;One suspects that you have a poorly designed process to start with. So go with the fact that you will not get a nice short bit of code to deal with such.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There might be a way with Proc IML but out of my experience and would require a much more complete description of your data. Since your provide an example data set then start adding other requirements (the variable B) as a counter example then a really representative data set is needed. Likely reshape (transpose) and summarize but you haven't really shown the expected results.&lt;/P&gt;</description>
      <pubDate>Wed, 09 Mar 2022 23:37:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-different-weights-on-the-same-variable-without/m-p/801199#M315298</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-03-09T23:37:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to use different weights on the same variable without intermediate datasteps or using proc s</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-different-weights-on-the-same-variable-without/m-p/801268#M315336</link>
      <description>&lt;P&gt;As output I need a dataset summarized by one ore more variable.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Writing another example&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Input dataset:&lt;/STRONG&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;options nolabel;

data pippo(drop=r);
	set sashelp.cars(keep=make model MSRP invoice enginesize cylinders horsepower length wheelbase
			 rename=(make=class1 model=class2 MSRP=a invoice=b enginesize=c
				 cylinders=wgt1 horsepower=wgt2 length=wgt3 wheelbase=wgt4)
			 );
	array wgt_(4) wgt1-wgt4; 

	do r=1 to 4;
	   wgt_(r)=sum(wgt_(r),0)/1000;*avoid missing with sum;
	end;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;So you have a starting dataset with 2 class variables (class1 and class2), 3 variables (a b c) that need to be weighted and summarized and then 4 weights.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Output dataset:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;I can achieve the output result trought a datastep (the part that I would like to remove):&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data pippo(drop=f a b c wgt1-wgt4);
	set pippo;

	array var(16) wgt1-wgt4 a1-a4 b1-b4 c1-c4;

	do f=1 to 4;
		var(f+4)=a*var(f);
		var(f+8)=b*var(f);
		var(f+12)=c*var(f);
	end;

run;

proc summary data=pippo missing nway;
        class class1;
        var a1-a4 b1-b4 c1-c4;
        output out=final (drop=_freq_ _type_) sum=;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;What I need is the dataset that is called "final".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Paolo&lt;/P&gt;</description>
      <pubDate>Thu, 10 Mar 2022 09:42:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-different-weights-on-the-same-variable-without/m-p/801268#M315336</guid>
      <dc:creator>Paolo_1981</dc:creator>
      <dc:date>2022-03-10T09:42:48Z</dc:date>
    </item>
  </channel>
</rss>

