12-13-2024
unwashedhelimix
Obsidian | Level 7
Member since
10-14-2024
- 18 Posts
- 5 Likes Given
- 0 Solutions
- 2 Likes Received
-
Latest posts by unwashedhelimix
Subject Views Posted 660 12-11-2024 12:15 AM 444 12-03-2024 02:57 AM 465 12-03-2024 02:25 AM 501 12-02-2024 10:11 PM 1051 12-02-2024 09:22 PM 1133 12-02-2024 05:39 PM 311 11-30-2024 10:58 PM 421 11-25-2024 04:44 AM 444 10-23-2024 12:08 AM 447 10-23-2024 12:06 AM -
Activity Feed for unwashedhelimix
- Posted Imputing the mean for missing the values on SAS Programming. 12-11-2024 12:15 AM
- Posted Re: Counting distinct inputs in a column using proc sql on SAS Programming. 12-03-2024 02:57 AM
- Posted Counting distinct inputs in a column using proc sql on SAS Programming. 12-03-2024 02:25 AM
- Liked Re: PROC TABULATE: Adding .PNG files & colors to an output for Ksharp. 12-03-2024 02:19 AM
- Posted PROC TABULATE: Adding .PNG files & colors to an output on SAS Programming. 12-02-2024 10:11 PM
- Liked Re: Renaming Colums in PROC SQL for Ksharp. 12-02-2024 09:57 PM
- Posted Re: Renaming Colums in PROC SQL on SAS Programming. 12-02-2024 09:22 PM
- Posted Renaming Colums in PROC SQL on SAS Programming. 12-02-2024 05:39 PM
- Posted Issue with the Title Date & Time on SAS Programming. 11-30-2024 10:58 PM
- Posted Issue with Sorting in Chronological Order on SAS Programming. 11-25-2024 04:44 AM
- Got a Like for Re: Where do arrays come in on this task?. 10-23-2024 07:32 AM
- Posted Re: Where do arrays come in on this task? on SAS Programming. 10-23-2024 12:08 AM
- Posted Re: Where do arrays come in on this task? on SAS Programming. 10-23-2024 12:06 AM
- Posted Where do arrays come in on this task? on SAS Programming. 10-22-2024 10:21 PM
- Posted How to Delete Entire Row if Conditions Are Met on SAS Programming. 10-21-2024 03:51 AM
- Posted Re: Getting a PDF Report All on One Page on SAS Programming. 10-21-2024 12:00 AM
- Posted Getting a PDF Report All on One Page on SAS Programming. 10-20-2024 10:51 PM
- Liked Re: Why is the time truncating and how do I fix it? for Ksharp. 10-20-2024 10:36 PM
- Posted Why is the time truncating and how do I fix it? on SAS Programming. 10-20-2024 09:23 PM
- Liked Re: Best Way to Do a Frequency Table for Patient Responses for PaigeMiller. 10-18-2024 01:39 PM
-
Posts I Liked
Subject Likes Author Latest Post 1 2 1 1 1 -
My Liked Posts
Subject Likes Posted 2 10-23-2024 12:08 AM
12-11-2024
12:15 AM
I merged 2 data sets, so that it adds a column to the other set by doing the following:
/* read datasets */
libname mysas "Path to file folder";
data mysas.Surveys;
set mysas.surveyresults;
run;
data mysas.APIdata;
set mysas.api;
run;
libname mysas "Path to file folder";
data surveys2;
set mysas.surveyresults;
if not missing(q1); /* Remove rows with missing inputs */
run;
data mergeddat;
merge surveys2 (in=inS) mysas.api (in=inA);
by SchoolName;
if inS; /* Keep only schools from the survey results */
run;
proc sort data=mergeddat;
by SchoolName;
run;
/* Verify added column */
proc print data=mergeddat (obs=5);
run;
/* Verify row count */
proc contents data=mergeddat;
run;
In this merged data, there is a column with missing values. For those values, I want to compute the mean of that column, and then impute that mean for the missing values. I'm trying to compute the mean and make it a global macro variable:
/* Compute the mean of q2 and create a global macro variable */
proc means data=mysas.Surveys noprint;
var q2;
output out=q2_mean_data mean=mean_q2;
run;
/* Extract the computed mean into a macro variable */
data _null_;
set q2_mean_data;
call symputx('q2_mean', mean_q2);
run;
/* Impute missing values in q2 using the computed mean */
data mysas.Surveys_Imputed;
set mysas.Surveys;
if missing(q2) then q2 = &q2_mean.;
run;
/* Step 3: Display the data with imputed values */
proc print data=mysas.Surveys_Imputed (obs=10); /* Display first 10 rows */
run;
However, when I try to get a visual, nothing is outputting when I do proc print. I feel like my logic and approach should accomplish this. What am I doing wrong and how can I fix this?
... View more
12-03-2024
02:57 AM
I tried this, but it looks like I am getting an error: ERROR: The following columns were not found in the contributing tables: "SPECIES NAME"n
However, when I remove the n, it runs again giving me the output of 1. I also added
option validvarname=any;
before the proc sql.
... View more
12-03-2024
02:25 AM
I have a SAS data set I read in:
libname mysas "path to datafile location";
data mysas.MyData;
set mysas.datafile;
run;
There is a column named "SPECIES NAME" that has many different types of species. I want to get a count of how many species there are, and here is what I did:
proc sql;
select count(distinct 'SPECIES NAME') as Number_of_Species
from mysas.MyData;
quit;
However, it tells me there is only 1 Number_of_Species. Looking at the data set, this is definitely not accurate. How can I fix this?
Because the 2nd (and 3rd I guess) thing I want to do is for each of the species, I want to get a count on how many years have been the data recorded for each species. Conversely, I also want to create an ordered list of all the years, then for each year, give the number of species that corresponds to that year.
There is a column in MyData called "YEAR" next to "SPECIES NAME" and it looks a bit like this: YEAR SPECIES NAME 2021 SPECIES A 2022 SPECIES A
2023 SPECIES A
2020 SPECIES B
2022 SPECIES B
I am not quite sure how I would approach that in proc sql.
... View more
12-02-2024
10:11 PM
I have the following code to create a report for a given data: data cutepets;
length pet $20;
input gender $ pet $ number_of_pets;
cards;
boy cockatiel 1
boy turtle 3
boy rabbit 4
girl cockatiel 2
girl turtle 3
girl rabbit 7
;
run;
title "Number of Cute Pets Owned by Families of 3rd Graders";
proc tabulate data=cutepets style=[just=center];
class gender pet;
var number_of_pets;
table gender='Gender',
pet='Pet' * number_of_pets='# of Pets' * sum=' ' /
box=' ' misstext='0';
run; My output then looks like this: How can I color certain cells and add pictures of a cockatiel, rabbit, and turtle? Something like this: Can I just add to my proc tabulate to add the colors and the images? Also, how can I move the "# of pets" to the spot in the 2nd output?
... View more
12-02-2024
09:22 PM
How can I input nicer strings? I tried this: proc sql;
create table temp as
select *
from product_data(rename=(prodnum='Product Number' prodname='Product Name'));
create table product_data as select * from temp;
quit;
title "Product Information";
proc print data=temp noobs;
run; but it doesn't rename the column headings. It works when I do something like prodnum=Product_Number, but I want spaces rather than underscores.
... View more
12-02-2024
05:39 PM
So, I have some data that looks like this: data product_data;
input prodnum $ 1-4 prodname $ 6-27 manunum $ 29-31 prodtype $ 33-43 rtlcost 45-49;
format rtlcost dollar8.2;
cards;
5119 Dream Machine 500 Workstation 3200
4216 Business Machine 450 Workstation 3215
5112 Office Phone 560 Phone 172
3110 Spreadsheet Software 134 Software 300
1230 Database Software 113 Software 757
3431 Statistical Software 243 Software 1789
2102 Wordprocessor Software 245 Software 423
;
run; I am running proc sql to apply price increase/decrease to some of the products: proc sql;
/* 20% price increase for all Software products */
update product_data
set rtlcost = rtlcost * 1.20
where prodtype = 'Software';
/* 20% price decrease for all other products */
update product_data
set rtlcost = rtlcost * 0.80
where prodtype not like 'Software';
quit;
proc print data=product_data noobs;
run; Is there a way to rename the column names in proc sql, and NOT in proc print or the data step? Like for example, renaming "prodnum" as Product Number, "prodname" as Product Name, "manunum" as Manufacturer Number, etc.
... View more
11-30-2024
10:58 PM
I have the following parts of some code I have: proc import datafile="FILE_PATH"
out=sample_data
dbms=csv
replace;
getnames=yes;
run;
/* get current date and time for titles in AM/PM format */
%let current_datetime = %sysfunc(datetime(), datetimeampm.);
proc sql;
create table my_output as
SQL Code
quit;
title1 "First Name & Last Name";
title2 "Date and Time: ¤t_datetime";
title3 "Title of Output";
proc print data=my_output;
run; However, the title2 in my output shows up as: Date and Time: 2048615388.473 Why isn't it showing in a MM/DD/YYYY AM/PM format? How can I fix it?
... View more
11-25-2024
04:44 AM
I have the following code: data docvisits;
input patientID $ weekday $ score;
cards;
101 Friday 15
163 Wednesday 11
104 Friday 23
163 Thursday 13
123 Tuesday 10
104 Monday 20
157 Friday 21
101 Monday 10
112 Tuesday 11
157 Tuesday 10
123 Monday 9
123 Friday 9
101 Tuesday 11
112 Monday 9
157 Thursday 18
174 Monday 12
;
proc format;
value $weekdayfmt
'Monday' = 1
'Tuesday' = 2
'Wednesday' = 3
'Thursday' = 4
'Friday' = 5;
run;
data docvisits_sorted;
set docvisits;
daynum = input(weekday, $weekdayfmt.);
run;
proc sql;
select weekday, count(distinct patientID) as Total_Patients
from docvisits_sorted
group by weekday
order by daynum;
quit; However, there is no output. My goal is to list the days of the week that visits were on and the total number of patients who visited each day. Prior to the one above, I tried: data docvisits;
input patientID$ weekday$5-13 score;
cards;
101 Friday 15
163 Wednesday 11
104 Friday 23
163 Thursday 13
123 Tuesday 10
104 Monday 20
157 Friday 21
101 Monday 10
112 Tuesday 11
157 Tuesday 10
123 Monday 9
123 Friday 9
101 Tuesday 11
112 Monday 9
157 Thursday 18
174 Monday 12
;
proc sql;
select weekday, count(distinct patientID) as Total_Patients
from docvisits
group by weekday;
quit; However, this does not output the days in chronological order. How can I fix my problem?
... View more
10-23-2024
12:08 AM
2 Likes
Ohp, I got it. Disregard!
... View more
10-23-2024
12:06 AM
Ahh, I see. I managed to code an array, but it outputs the scores for both Knee 1 and Knee 2. Is there a way to implement a conditional statement, where it's like "if Knee_1or2 = 2, then do not include this row in the output?"
... View more
10-22-2024
10:21 PM
I have a data set that looks like this: data SurgerySatisfaction;
input ID$ Knee_1or2$ Score_PreOp Score_1Day Score_1Week Score_1Month;
cards;
01 1 0 5 7 10
02 1 0 10 15 15
02 2 3 5 8 10
03 1 0 3 3 3
03 2 0 6 9 9
04 1 0 4 10 10
;
run; Basically, the data set records patient ID, which knee got replacement surgery (1 or 2), and satisfaction scores at a certain time before/after the surgery. The task then asked to use the array staatement to create a new data set that contains satisfaction scores for knee 1, and the output is supposed to look like this: id visit score
01 1 0
01 2 5
01 3 7
01 4 10
02 1 0
02 2 10
02 3 15
02 4 15
03 1 0
03 2 3
03 3 3
03 4 3
04 1 0
04 2 4
04 3 10
04 4 10 How is this acheived by the array statement? I guess I also need to better understand what the whole point of array statements is.
... View more
10-21-2024
03:51 AM
I have a concatenated data set from 2 data sets that looks something like this: ID Gender Starting_Weight End_Weight
1 M 170 180
2 M 182 175
3 M 155 162
4 M 203 196
5 F 124 135
6 F 152 155
7 F 118 133
8 F 160 152 There are more observations, but what I want to do is remove all rows where the change between the weights is less than 10. Here is my atttempt: data WeightsCombined;
set WeightsMale WeightsFemale;
Weight_change = sum(-Starting_Weight, End_Weight);
if Weight_change<10 then delete;
run;
proc print data = WeightsCombined;
run; For some reason, this outputs nothing. Why is an output not showing and how can I remove the rows that meet my condition?
... View more
10-21-2024
12:00 AM
What is the proc freq for? I tried out the papersize options and the style, but the report wasn't quite in a format like below:
... View more
10-20-2024
10:51 PM
I have a csv data set that looks something like this: Now, I am looking to produce a PDF report that has all of the state info in the data set on one page like this: The code I have to attempt this is the following: proc import datafile = "path to csv file"
out=StateDataSet
dbms=csv
replace;
run;
ods pdf file = "path to store pdf file";
proc print data = StateDataSet NOOBS label;
format Area Comma7.0 Population Comma10.0;
title ;
label State_Name = 'State Name';
label State_Abbrev = 'State Abbrev.';
label Postal_Abbrev = 'Postal Abbrev.';
label Area = 'Area (Sq Mi)';
run;
ods pdf close; However, the PDF produced stretches 2 pages, and it is in a table format. How can I format it, so that it is all in one page and it doesn't come out in the table format to replicate the example?
... View more
10-20-2024
09:23 PM
I have data on earthquakes that look something like this: Date Time Magnitude Latitude Longitude
2022/01/10 14:54:28.81 0.36 33.512 -116.768
2022/01/10 15:16:32.60 0.96 33.184 -116.031
2022/01/10 15:43:09.41 1.09 35.680 -117.535
2022/01/10 16:33:07.48 0.68 33.588 -116.808
2022/01/10 17:14:17.90 0.86 36.032 -117.807
2022/01/10 18:00:07.32 0.61 35.765 -117.580
2022/01/10 18:50:47.06 0.90 35.586 -117.462
2022/01/10 18:59:47.00 2.61 35.648 -115.927 I want to print the report showing MM/DD/YYYY date format and AM/PM date format, and my code is below: data Earthquakes;
infile "path to .txt file";
input Date yymmdd10. Time time11. Magnitude $ Latitude Longitude $;
format Date mmddyy10. Time timeampm.;
run;
proc print data = Earthquakes;
run; However, the output cuts off the milliseconds part of Time, rounds it to the nearest integer, and then puts it in the Magnitude column. The output looks something like this: Why is the milliseconds part of time being put in the magnitude column, and then shifting every input one column over? How can I revise the code to show the time in AM/PM while having the correct entries in the magnitude, latitude, and longitude columns?
... View more