<?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: Data step. Taking observations from different tables, and rename them. in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Data-step-Taking-observations-from-different-tables-and-rename/m-p/543984#M7782</link>
    <description>&lt;P&gt;Show test data before means output, in the form of a datastep, and what the output should look like.&amp;nbsp; Its seems a bit of a faff and you may be able to simplfy the whole thing by normalising before means processing.&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Oh, and please stop shouting code at us.&lt;/P&gt;</description>
    <pubDate>Mon, 18 Mar 2019 14:01:00 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2019-03-18T14:01:00Z</dc:date>
    <item>
      <title>Data step. Taking observations from different tables, and rename them.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Data-step-Taking-observations-from-different-tables-and-rename/m-p/543950#M7775</link>
      <description>&lt;P&gt;Hi there, I am trying to create a data using data step, based on PROC MEANS OUTPUT (means_all table) AND REGRESS OUTPUT (estimates table). The thing is that I have multiple values as I used the CLASS statement in both of them. The next picture shows three categories, AG, MAN and SR and below the means for the variables R and L.&amp;nbsp; I need to take all the means for each class so,&amp;nbsp;together with the estimates I can compute some operations.&amp;nbsp; I have done this before but just having one class using&amp;nbsp;first obs and keep, but having Classes it did not work. This is my shot.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA WANT;
	 SET ESTIMATES;
	IF _N_ = 1 THEN DO;
		SET MEANS_ALL (FIRSTOBS = 2 KEEP = R_MEAN L_MEAN);
					RENAME R_MEAN = R_MEAN_AG;
					RENAME LNTA_MEAN = L_MEAN_AG;
		SET MEANS_ALL (FIRSTOBS = 3 KEEP = R_MEAN L_MEAN);
					RENAME ROA_MEAN = R_MEAN_MAN;
					RENAME LNTA_MEAN = L_MEAN_MAN ;
		SET MEANS_ALL (FIRSTOBS = 5 KEEP = R_MEAN L_MEAN);
					RENAME ROA_MEAN = R_MEAN_SR;
					RENAME LNTA_MEAN = L_MEAN_SR ;
END;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.JPG" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/28011i1930CC581FD5D3EC/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.JPG" alt="Capture.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 18 Mar 2019 11:55:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Data-step-Taking-observations-from-different-tables-and-rename/m-p/543950#M7775</guid>
      <dc:creator>OscarUvalle</dc:creator>
      <dc:date>2019-03-18T11:55:14Z</dc:date>
    </item>
    <item>
      <title>Re: Data step. Taking observations from different tables, and rename them.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Data-step-Taking-observations-from-different-tables-and-rename/m-p/543954#M7777</link>
      <description>&lt;P&gt;Couldn't you transpose the means output and then join with the estimates on response and variable?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Something like&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc transpose
  data=means
  out=means_trans (
    rename=(_name_=variable col1=mean)
  )
;
by response;
var _numeric_;
run;

proc sql;
create table want as
select a.*, b.mean
from estimates a left join means_trans b
on a.variable = b.variable and a.response = b.response;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 18 Mar 2019 12:33:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Data-step-Taking-observations-from-different-tables-and-rename/m-p/543954#M7777</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-03-18T12:33:05Z</dc:date>
    </item>
    <item>
      <title>Re: Data step. Taking observations from different tables, and rename them.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Data-step-Taking-observations-from-different-tables-and-rename/m-p/543960#M7779</link>
      <description>&lt;P&gt;Can you show us what the desired output would look like?&lt;/P&gt;</description>
      <pubDate>Mon, 18 Mar 2019 12:25:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Data-step-Taking-observations-from-different-tables-and-rename/m-p/543960#M7779</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-03-18T12:25:23Z</dc:date>
    </item>
    <item>
      <title>Re: Data step. Taking observations from different tables, and rename them.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Data-step-Taking-observations-from-different-tables-and-rename/m-p/543984#M7782</link>
      <description>&lt;P&gt;Show test data before means output, in the form of a datastep, and what the output should look like.&amp;nbsp; Its seems a bit of a faff and you may be able to simplfy the whole thing by normalising before means processing.&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Oh, and please stop shouting code at us.&lt;/P&gt;</description>
      <pubDate>Mon, 18 Mar 2019 14:01:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Data-step-Taking-observations-from-different-tables-and-rename/m-p/543984#M7782</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2019-03-18T14:01:00Z</dc:date>
    </item>
    <item>
      <title>Re: Data step. Taking observations from different tables, and rename them.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Data-step-Taking-observations-from-different-tables-and-rename/m-p/544541#M7865</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&lt;BR /&gt;data WORK.DATA;
  infile datalines dsd truncover;
  input ID:BEST. SEC:$3. R:COMMA15.4 L:BEST. E:COMMA15.4;
  format ID BEST. R COMMA15.4 L BEST. E COMMA15.4;
  label ID="ID" SEC="SEC" R="R" L="L" E="E";
datalines;
1115 OTH 0.0032 10.684656256 0.0095
1494 OTH 0.0025 12.517256378 0.0000
1498 SER 0.0026 10.138639711 0.0327
1501 MAN 0.0028 9.564539273 0.0001
1515 MAN 0.0047 11.239027947 0.0967
;;;;
/* step 1. Estimates */
proc logistic data = data plots = none	outest = mlogit_estimates; 
	 model sec (ref = 'oth')= r l e / link = glogit ; run;
/* step 2. Means */
proc means data = data mean maxdec = 4 ; class sec ; output out = means_all	mean = average / autoname ; run;

/* step 3 create a data set where both tables are combined */
data partial;
	set 
		mlogit_estimates (drop = _link_ _type_ _status_ _name_ _lnlike_ _esttype_)
		means_all ;
		if (sec = 'agr') then 
						rename r_mean = r_mean_agr
							   l_mean = l_mean_agr 
                               e_mean_agr;
					
		if (sec = 'man') then 	
						rename r_mean = r_mean_man 
							   l_mean = l_mean_man 
	                           e_mean_man;
						
		if (sec = 'ser') then 
						rename r_mean = r_mean_ser 
							   l_mean = l_mean_ser 
                               e_mean_ser;
					
		step_1_agr = exp (r_estimate_agr * r_mean_agr * l_mean_agr);
		step_2_man = exp (l_estimate_man * l_mean_man);
		step_3_ser = exp (0);

		prob_agr = (step_1_agr / (1 +  step_1_agr + step_2_man + step_3_ser));
		prob_man = (step_2_man / (1 +  step_1_agr + step_2_man + step_3_ser));
		prob_ser = (step_3_ser / (1 +  step_1_agr + step_2_man + step_3_ser));

		par_der_agr = e_estimate_agr(prob_agr)( 1 - prob_agr);
		par_der_man = e_estimate_man(prob_man)( 1 - prob_man);
		par_der_ser = eq_estimate_ser(prob_ser)( 1 - prob_ser);
run;

proc print data = partial label noobs; var par_der_agr ; format _all_ comma15.4 ; run;
proc print data = partial label noobs; var par_der_man ; format _all_ comma15.4 ; run;
proc print data = partial label noobs; var par_der_ser ; format _all_ comma15.4 ; run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sorry for the late response. So many events yesterday. I am trying to increase my SAS skills but I am still in baby steps. I have put the code and the formulas or steps I need to do to get my results. The only thing I am still struggling is the fact that I can get me variables in the same table and use them on my steps.&amp;nbsp;&lt;/P&gt;&lt;P&gt;My data partial does not work as I am trying to rename the variables by sector so I can use them in the step below.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;the transpose means it indeed works but no the SQL. Still, the data in means_trans is not handy as I need (that's my perception maybe it is). By the way, very good article, Maxims of Maximally... I am printing it to make my bible.&lt;/P&gt;&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;I am looking values such as, (of course including the whole data)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;P(AGR)&lt;/TD&gt;&lt;TD&gt;0.175088&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;P(MAN)&lt;/TD&gt;&lt;TD&gt;0.237825&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;P(SER)&lt;/TD&gt;&lt;TD&gt;0.293544&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/45151"&gt;@RW9&lt;/a&gt;&amp;nbsp;I have put now the code now so ya can see what I am trying to do. On the other hand, I did not mean to shout code to you all, I just like the way how my SAS code looks in capital letters. In future post, I will be aware of it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you all&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Mar 2019 13:01:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Data-step-Taking-observations-from-different-tables-and-rename/m-p/544541#M7865</guid>
      <dc:creator>OscarUvalle</dc:creator>
      <dc:date>2019-03-20T13:01:26Z</dc:date>
    </item>
  </channel>
</rss>

