MBlack732 Tracker
https://communities.sas.com/kntur85557/tracker
MBlack732 TrackerMon, 15 Apr 2024 03:24:52 GMT2024-04-15T03:24:52ZRe: Need help with merged data set
https://communities.sas.com/t5/SAS-Procedures/Need-help-with-merged-data-set/m-p/511446#M73066
<P>Perfect! Thank you so much! Such a simple fix, I feel foolish that I missed it! Thanks again for the help!</P>Thu, 08 Nov 2018 17:07:31 GMThttps://communities.sas.com/t5/SAS-Procedures/Need-help-with-merged-data-set/m-p/511446#M73066MBlack7322018-11-08T17:07:31ZNeed help with merged data set
https://communities.sas.com/t5/SAS-Procedures/Need-help-with-merged-data-set/m-p/511438#M73064
<P>Hello!</P><P>For an assignment, we merged two data sets "bp" (which include subject, date of visit, SBP and DBP; there were multiple observations per subject) and "demog" (which include variables like date of birth, date of entering the study, marital status, education, smoking, and drinking). I need to make sure that the subjects are all under the age of 55 and the blood pressure readings considered are only from the first visit date. So far in my code I did:</P><P> </P><P>LIBNAME BIST0535 "C:\Users\Paula\Desktop\BIST0535";</P><P> </P><P><STRONG>*Narrowing down blood pressure data to first visit only*</STRONG></P><P>DATA BIST0535.bp_hw3_1;</P><P> SET BIST0535.bp_hw3;</P><P>RUN;</P><P> </P><P>PROC SORT Data=BIST0535.bp_hw3_1;</P><P> BY subject;</P><P>RUN;</P><P> </P><P>DATA BIST0535.bp_hw3_2;</P><P> SET BIST0535.bp_hw3_1;</P><P> BY subject;</P><P> IF FIRST.subject;</P><P>RUN;</P><P> </P><P><STRONG>*Merging of Datasets and narrowing subject list to people younger than 55*</STRONG></P><P>DATA BIST0535.HW3;</P><P> SET BIST0535.demog_hw3 BIST0535.bp_hw3_2;</P><P> age = (doe-dob)/365.25;</P><P> IF age GT 55 THEN DELETE;</P><P>RUN;</P><P> </P><P><STRONG>*Looking at relationship between marital status and smoking/drinking*</STRONG></P><P>PROC SORT DATA= BIST0535.HW3;</P><P> BY marital;</P><P>RUN;</P><P> </P><P>PROC FREQ DATA= BIST0535.HW3;</P><P> TABLES smoke drink smoke*drink;</P><P> BY marital;</P><P> TITLE "HW3 Frequencies of smoke, drink, and smoke*drink by marital status";</P><P>RUN;</P><P> </P><P>Now I want to look at the relationship between educational attainment (education) and blood pressure readings (SBP and DBP), by looking at the break down of frequencies, as I did above with marital and smoking/drinking. However it is not working and I believe it is because the way the data was merged. Even if the subject is the same, the variables from the two different original data sets are appearing on separate observations. Here is a section of the proc print (I italicized subject 1, as it exemplifies this issue):</P><P> </P><DIV class="branch"><DIV><DIV align="center">Obs subject site gender dob doe smoke drink marital education dov dbp sbp age <TABLE cellspacing="0" cellpadding="5"><TBODY><TR><TD><EM>1</EM></TD><TD><EM>.</EM></TD><TD><EM> </EM></TD><TD><EM>.</EM></TD><TD><EM>.</EM></TD><TD><EM>.</EM></TD><TD><EM>.</EM></TD><TD><EM>.</EM></TD><TD><EM>.</EM></TD><TD><EM>14145</EM></TD><TD><EM>107</EM></TD><TD><EM>134</EM></TD><TD><EM>.</EM></TD></TR><TR><TD><EM>1</EM></TD><TD><EM>5</EM></TD><TD><EM>F</EM></TD><TD><EM>-1092</EM></TD><TD><EM>14069</EM></TD><TD><EM>0</EM></TD><TD><EM>2</EM></TD><TD><EM>3</EM></TD><TD><EM>3</EM></TD><TD><EM>.</EM></TD><TD><EM>.</EM></TD><TD><EM>.</EM></TD><TD><EM>41.5086</EM></TD></TR><TR><TD>2</TD><TD>.</TD><TD> </TD><TD>.</TD><TD>.</TD><TD>.</TD><TD>.</TD><TD>.</TD><TD>.</TD><TD>14447</TD><TD>115</TD><TD>143</TD><TD>.</TD></TR><TR><TD>3</TD><TD>.</TD><TD> </TD><TD>.</TD><TD>.</TD><TD>.</TD><TD>.</TD><TD>.</TD><TD>.</TD><TD>14082</TD><TD>103</TD><TD>148</TD><TD>.</TD></TR><TR><TD>4</TD><TD>.</TD><TD> </TD><TD>.</TD><TD>.</TD><TD>.</TD><TD>.</TD><TD>.</TD><TD>.</TD><TD>14632</TD><TD>87</TD><TD>110</TD><TD>.</TD></TR><TR><TD>4</TD><TD>1</TD><TD>F</TD><TD>892</TD><TD>14632</TD><TD>0</TD><TD>5</TD><TD>2</TD><TD>3</TD><TD>.</TD><TD>.</TD><TD>.</TD><TD>37.6181</TD></TR><TR><TD>5</TD><TD>.</TD><TD> </TD><TD>.</TD><TD>.</TD><TD>.</TD><TD>.</TD><TD>.</TD><TD>.</TD><TD>14650</TD><TD>66</TD><TD>108</TD><TD>.</TD></TR><TR><TD>5</TD><TD>2</TD><TD>F</TD><TD>259</TD><TD>14558</TD><TD>0</TD><TD>2</TD><TD>1</TD><TD>2</TD><TD>.</TD><TD>.</TD><TD>.</TD><TD>39.1485</TD></TR><TR><TD>6</TD><TD>.</TD><TD> </TD><TD>.</TD><TD>.</TD><TD>.</TD><TD>.</TD><TD>.</TD><TD>.</TD><TD>14520</TD><TD>75</TD><TD>133</TD><TD>.</TD></TR><TR><TD>6</TD><TD>4</TD><TD>F</TD><TD>1809</TD><TD>14429</TD><TD>1</TD><TD>2</TD><TD>3</TD><TD>3</TD><TD>.</TD><TD>.</TD><TD>.</TD><TD>34.5517</TD></TR><TR><TD>7</TD><TD>.</TD><TD> </TD><TD>.</TD><TD>.</TD><TD>.</TD><TD>.</TD><TD>.</TD><TD>.</TD><TD>14813</TD><TD>87</TD><TD>131</TD><TD>.</TD></TR><TR><TD>7</TD><TD>3</TD><TD>M</TD><TD>-3979</TD><TD>14637</TD><TD>0</TD><TD>2</TD><TD>3</TD><TD>2</TD><TD>.</TD><TD>.</TD><TD>.</TD><TD>50.9678</TD></TR><TR><TD>8</TD><TD>.</TD><TD> </TD><TD>.</TD><TD>.</TD><TD>.</TD><TD>.</TD><TD>.</TD><TD>.</TD><TD>14285</TD><TD>112</TD><TD>149</TD><TD>.</TD></TR><TR><TD>8</TD><TD>5</TD><TD>M</TD><TD>-3669</TD><TD>14285</TD><TD>0</TD><TD>4</TD><TD>2</TD><TD>3</TD><TD>.</TD><TD>.</TD><TD>.</TD><TD>49.1554</TD></TR><TR><TD>9</TD><TD>.</TD><TD> </TD><TD>.</TD><TD>.</TD><TD>.</TD><TD>.</TD><TD>.</TD><TD>.</TD><TD>14865</TD><TD>84</TD><TD>123</TD><TD>.</TD></TR><TR><TD>9</TD><TD>3</TD><TD>F</TD><TD>2438</TD><TD>14618</TD><TD>0</TD><TD>3</TD><TD>3</TD><TD>3</TD><TD>.</TD><TD>.</TD><TD>.</TD><TD>33.3470</TD></TR><TR><TD>10</TD><TD>.</TD><TD> </TD><TD>.</TD><TD>.</TD><TD>.</TD><TD>.</TD><TD>.</TD><TD>.</TD><TD>13967</TD><TD>88</TD><TD>120</TD></TR></TBODY></TABLE><P> </P><P><U><EM><STRONG>HOW DO I FIX THIS PLEASE?</STRONG></EM></U></P></DIV></DIV></DIV>Thu, 08 Nov 2018 16:44:17 GMThttps://communities.sas.com/t5/SAS-Procedures/Need-help-with-merged-data-set/m-p/511438#M73064MBlack7322018-11-08T16:44:17ZRe: Creating new set with only one observation per subject from last set
https://communities.sas.com/t5/SAS-Procedures/Creating-new-set-with-only-one-observation-per-subject-from-last/m-p/510575#M73009
<P>Thank you! For some reason it was giving me an error about the BY statement, but i guess there was a need for a PROC SORT before this could occur.</P>Mon, 05 Nov 2018 19:44:10 GMThttps://communities.sas.com/t5/SAS-Procedures/Creating-new-set-with-only-one-observation-per-subject-from-last/m-p/510575#M73009MBlack7322018-11-05T19:44:10ZCreating new set with only one observation per subject from last set
https://communities.sas.com/t5/SAS-Procedures/Creating-new-set-with-only-one-observation-per-subject-from-last/m-p/510559#M73006
<P>this is from BIST0535.hw3_1</P><P>As you can see I have sorted data by subject and then dov, such that the observations for a single subject are all clumped together and the observation from the first time they visited (date of visit, dov) is first. I need to create a new data set BIST0535.hw3_2 which contains only one observation from each subject with the first time they visited. I think we are meant to use an IF THEN statement, however if there is a easier way I am open to it.</P><DIV class="branch"><DIV><DIV align="center">Obs subject dov dbp sbp <TABLE cellspacing="0" cellpadding="5"><TBODY><TR><TD>1</TD><TD>07/09/1998</TD><TD>108</TD><TD>157</TD></TR><TR><TD>1</TD><TD>09/23/1998</TD><TD>107</TD><TD>134</TD></TR><TR><TD>2</TD><TD>10/15/1998</TD><TD>114</TD><TD>149</TD></TR><TR><TD>2</TD><TD>01/14/1999</TD><TD>112</TD><TD>165</TD></TR><TR><TD>2</TD><TD>04/15/1999</TD><TD>105</TD><TD>158</TD></TR><TR><TD>2</TD><TD>07/22/1999</TD><TD>115</TD><TD>143</TD></TR><TR><TD>3</TD><TD>07/22/1998</TD><TD>103</TD><TD>148</TD></TR><TR><TD>3</TD><TD>10/07/1998</TD><TD>107</TD><TD>165</TD></TR><TR><TD>3</TD><TD>01/14/1999</TD><TD>102</TD><TD>159</TD></TR><TR><TD>4</TD><TD>01/23/2000</TD><TD>87</TD><TD>110</TD></TR><TR><TD>4</TD><TD>04/26/2000</TD><TD>85</TD><TD>128</TD></TR><TR><TD>5</TD><TD>11/10/1999</TD><TD>65</TD><TD>137</TD></TR><TR><TD>5</TD><TD>02/10/2000</TD><TD>66</TD><TD>108</TD></TR></TBODY></TABLE></DIV></DIV></DIV>Mon, 05 Nov 2018 19:17:48 GMThttps://communities.sas.com/t5/SAS-Procedures/Creating-new-set-with-only-one-observation-per-subject-from-last/m-p/510559#M73006MBlack7322018-11-05T19:17:48ZHow to create a .sas or .txt file for your code?
https://communities.sas.com/t5/SAS-Procedures/How-to-create-a-sas-or-txt-file-for-your-code/m-p/508041#M72886
<P>For an assignment I created a SAS Code but the professor wants to see it in either a .sas or .txt file. How do we do this within the SAS program? </P>Sat, 27 Oct 2018 23:23:49 GMThttps://communities.sas.com/t5/SAS-Procedures/How-to-create-a-sas-or-txt-file-for-your-code/m-p/508041#M72886MBlack7322018-10-27T23:23:49ZRe: IF THEN statement with a combination of variables
https://communities.sas.com/t5/SAS-Procedures/IF-THEN-statement-with-a-combination-of-variables/m-p/508008#M72881
<P>I tried this code:</P><P> </P><P>IF pregnancy=1 AND gender=M THEN cat=0;<BR />ELSE IF pregnancy=9 and gender=M THEN cat=0;<BR />ELSE IF pregnancy=9 and gender=F THEN cat=0;<BR />ELSE IF pregnancy=1 and gender=F THEN cat=1;<BR />ELSE IF pregnacy=0 and gender=F THEN cat=1;<BR />ELSE IF pregnancy=0 and gender=M THEN cat=1;</P><P> </P><P>and my log resulted in this error message:</P><P>206 IF pregnancy=1 AND gender=M THEN cat=0;<BR />--<BR />180</P><P>ERROR 180-322: Statement is not valid or it is used out of proper order.</P><P>207 ELSE IF pregnancy=9 and gender=M THEN cat=0;<BR />----<BR />180</P><P>ERROR 180-322: Statement is not valid or it is used out of proper order.</P><P>208 ELSE IF pregnancy=9 and gender=F THEN cat=0;<BR />----<BR />180</P><P>ERROR 180-322: Statement is not valid or it is used out of proper order.</P><P>209 ELSE IF pregnancy=1 and gender=F THEN cat=1;<BR />----<BR />180</P><P>ERROR 180-322: Statement is not valid or it is used out of proper order.</P><P>210 ELSE IF pregnacy=0 and gender=F THEN cat=1;<BR />----<BR />180</P><P>ERROR 180-322: Statement is not valid or it is used out of proper order.</P><P>211 ELSE IF pregnancy=0 and gender=M THEN cat=1;<BR />----<BR />180</P><P>ERROR 180-322: Statement is not valid or it is used out of proper order.</P><P> </P>Sat, 27 Oct 2018 18:10:03 GMThttps://communities.sas.com/t5/SAS-Procedures/IF-THEN-statement-with-a-combination-of-variables/m-p/508008#M72881MBlack7322018-10-27T18:10:03ZIF THEN statement with a combination of variables
https://communities.sas.com/t5/SAS-Procedures/IF-THEN-statement-with-a-combination-of-variables/m-p/508004#M72879
<P>Hi! </P><P>I'm working with a data set and I'm trying to see if any of the pregnancy responses are invalid based on gender (i.e. male participants should not be recorded as having ever been pregnant). </P><P>The values are as follows:</P><P> </P><P>GENDER</P><P>M=Male </P><P>F= Female</P><P> </P><P>PREGNANCY</P><P>0=never been pregnant</P><P>1=has been or is pregnant</P><P>9=not available</P><P> </P><P>How do I write an IF THEN statement where if the participant is a man and has been pregnant than his category is 0 but any other combination of the two variables is category 1?</P>Sat, 27 Oct 2018 17:54:32 GMThttps://communities.sas.com/t5/SAS-Procedures/IF-THEN-statement-with-a-combination-of-variables/m-p/508004#M72879MBlack7322018-10-27T17:54:32ZRe: How to output data set to a text file with only the first observation per subject?
https://communities.sas.com/t5/SAS-Procedures/ONLY-WANT-1-OBSERVATION-with-MAX-response-for-one-variable-by/m-p/506201#M72825
<P>this only changes the variable name for me, it doesn't actually get rid of the other observations</P><P>but thanks!</P>Sat, 20 Oct 2018 02:28:00 GMThttps://communities.sas.com/t5/SAS-Procedures/ONLY-WANT-1-OBSERVATION-with-MAX-response-for-one-variable-by/m-p/506201#M72825MBlack7322018-10-20T02:28:00ZONLY WANT 1 OBSERVATION with MAX response for one variable by subject
https://communities.sas.com/t5/SAS-Procedures/ONLY-WANT-1-OBSERVATION-with-MAX-response-for-one-variable-by/m-p/506195#M72823
<P>Hello! I'm trying to create a text file with this data set, that I have sorted by subject and then in descending order by glucose level. I will attach the data set now...</P><P>subject female glucose Visit_Date Age</P><TABLE cellspacing="0" cellpadding="5"><TBODY><TR><TD>1</TD><TD>0</TD><TD>142</TD><TD>14860</TD><TD>59.9754</TD></TR><TR><TD>1</TD><TD>0</TD><TD>139</TD><TD>14579</TD><TD>59.2060</TD></TR><TR><TD>1</TD><TD>0</TD><TD>136</TD><TD>14662</TD><TD>59.4333</TD></TR><TR><TD>1</TD><TD>0</TD><TD>134</TD><TD>14765</TD><TD>59.7153</TD></TR><TR><TD>4</TD><TD>1</TD><TD>101</TD><TD>14478</TD><TD>38.3025</TD></TR><TR><TD>4</TD><TD>1</TD><TD>100</TD><TD>14392</TD><TD>38.0671</TD></TR><TR><TD>8</TD><TD>1</TD><TD>124</TD><TD>14129</TD><TD>48.4271</TD></TR><TR><TD>8</TD><TD>1</TD><TD>115</TD><TD>14222</TD><TD>48.6817</TD></TR><TR><TD>11</TD><TD>1</TD><TD>94</TD><TD>14006</TD><TD>31.5127</TD></TR><TR><TD>11</TD><TD>1</TD><TD>89</TD><TD>14082</TD><TD>31.7207</TD></TR><TR><TD>14</TD><TD>1</TD><TD>135</TD><TD>14351</TD><TD>60.6899</TD></TR><TR><TD>14</TD><TD>1</TD><TD>128</TD><TD>14632</TD><TD>61.4593</TD></TR><TR><TD>14</TD><TD>1</TD><TD>127</TD><TD>14536</TD><TD>61.1964</TD></TR><TR><TD>14</TD><TD>1</TD><TD>126</TD><TD>14438</TD><TD>60.9281</TD></TR><TR><TD>15</TD><TD>1</TD><TD>99</TD><TD>14283</TD><TD>44.3997</TD></TR><TR><TD>15</TD><TD>1</TD><TD>95</TD><TD>14183</TD><TD>44.1259</TD></TR><TR><TD>15</TD><TD>1</TD><TD>91</TD><TD>14387</TD><TD>44.6845</TD></TR><TR><TD>16</TD><TD>1</TD><TD>70</TD><TD>13971</TD><TD>28.2409</TD></TR><TR><TD>20</TD><TD>0</TD><TD>161</TD><TD>14265</TD><TD>62.3107</TD></TR><TR><TD>20</TD><TD>0</TD><TD>150</TD><TD>14350</TD><TD>62.5435</TD></TR></TBODY></TABLE><P> </P><P>My code so far is this...</P><P> </P><P>LIBNAME BIST0535 "C:\Users\Paula\Desktop\BIST0535";</P><P> </P><P>DATA BIST0535.hw2;<BR /> SET BIST0535.hw2_data(RENAME= (dov=Visit_Date));<BR /> Age= (Visit_Date-dob)/365.25;<BR /> IF state NE 4 then delete;<BR />RUN;</P><P> </P><P>PROC SORT;<BR /> BY subject DESCENDING glucose;<BR />RUN;</P><P> </P><P>PROC PRINT;<BR /> VAR subject female glucose visit_date age;<BR />RUN;</P><P> </P><P> </P><P> </P><P>Now I'm trying to output this data set into a text file, but I only want one observation to appear per subject and I want only the maximum glucose level (the first observation per subject) to appear.<STRONG> Essentially, the assignment is to only show the observation with the maximum glucose level per subject. How do I get it to look more like this....</STRONG></P><P> </P><P><STRONG>OBS SUBJECT FEMALE MAX_GLUCOSE VISIT_DATE AGE</STRONG></P><P> 1 1 0 142 7 September 2000 59.98</P><P> 2 4 1 101 22 August 1999 38.30</P><P> 3 8 1 124 7 September 1998 48.43</P><P>etc...</P><P> </P><DIV class="branch"><DIV align="center"> </DIV></DIV>Sat, 20 Oct 2018 02:27:05 GMThttps://communities.sas.com/t5/SAS-Procedures/ONLY-WANT-1-OBSERVATION-with-MAX-response-for-one-variable-by/m-p/506195#M72823MBlack7322018-10-20T02:27:05ZRe: Finding max value of a variable for a certain subject ID that has multiple observations
https://communities.sas.com/t5/SAS-Procedures/Finding-max-value-of-a-variable-for-a-certain-subject-ID-that/m-p/505712#M72808
<P>Perfect! Thank you!</P><P>I'm pretty new to SAS (first-year grad student), so I always get excited to see a log with no error messages!</P><P>Thank you, again!</P>Thu, 18 Oct 2018 19:13:29 GMThttps://communities.sas.com/t5/SAS-Procedures/Finding-max-value-of-a-variable-for-a-certain-subject-ID-that/m-p/505712#M72808MBlack7322018-10-18T19:13:29ZFinding max value of a variable for a certain subject ID that has multiple observations
https://communities.sas.com/t5/SAS-Procedures/Finding-max-value-of-a-variable-for-a-certain-subject-ID-that/m-p/505683#M72804
<P>Hello!</P><P>I'm trying to find max glucose level per subject, but the subjects have multiple variables.</P><P> </P><P>For example:</P><P>DATA homework2;</P><P>INPUT subject $ visit_date glucose;</P><P>DATALINES;</P><P>1 06/14/16 113</P><P>2 05<SPAN>/21/16 107</SPAN></P><P>3 08<SPAN>/17/17 98</SPAN></P><P>1 12<SPAN>/01/17 110</SPAN></P><P>2 03<SPAN>/21/17 118</SPAN></P><P>3 04<SPAN>/04/17 106</SPAN></P><P><SPAN>1 01/23/18 117</SPAN></P><P><SPAN>;</SPAN></P><P><SPAN>RUN;</SPAN></P><P> </P><P><SPAN>How do I get the system to realize that the different subjects occur at different frequencies and across separate observations but I want the maximum glucose value IN A NEW VARIABLE (max_glucose) per subject?</SPAN></P><P> </P><P> </P>Thu, 18 Oct 2018 18:22:03 GMThttps://communities.sas.com/t5/SAS-Procedures/Finding-max-value-of-a-variable-for-a-certain-subject-ID-that/m-p/505683#M72804MBlack7322018-10-18T18:22:03Z