Posts

Showing posts with the label sas

How to keep single quote when importing Excel data to SAS

Image
Clash Royale CLAN TAG #URR8PPP How to keep single quote when importing Excel data to SAS I am importing an Excel spreadsheet into SAS using Proc Import: Proc Import out=OUTPUT Datafile = "(filename)" DBMS=XLSX Replace; Range = "Sheet1$A:Z"; run; My numeric data columns contain a mixture of values held in Excel as numerics and '0 values held as text - i.e. with a leading apostrophe / single quote. When SAS imports these it treats them all the same (i.e. it returns Character strings of the values with the leading apostrophe stripped out). This results in differences from the spreadsheet when calculations are applied (e.g. averaging) as Excel treats the '0 values as missing but SAS treats them as 0. Is it possible to import the values as strings including the leading single quote / apostrophe, so that I can replace the '0 with missing values but keep the 0 records as 0? I would like to avoid having to manually manipulate the data in Excel as this data is...

SAS: Grouping by ID and summing the number of a condition in a variable for the ID

Image
Clash Royale CLAN TAG #URR8PPP SAS: Grouping by ID and summing the number of a condition in a variable for the ID I have a dataset that contains the ID and a variable called CC. The CC holds multiple numbered values where each value represents something. It looks like this: An ID can have the same CC in multiple rows, I just want to flag if the CC exists or not so even if Joe had five rows stating that he has CC equal to 3 I just want a 1 or 0 stating if Joe ever had a CC equal to 3. I want it to look like this: I tried coding it as shown below but the issue is that although I know an ID can have more than one type of CC the final dataset that's created from the code only shows 1 CC for each ID that is filled. I think maybe it's overwriting it? Also I should note that prior to this code I created the CC Flag variables and filled it all as zeros. proc sql; DROP TABLE Flagged_CCs; CREATE TABLE Flagged_CCs AS select ID, COUNT(ID) as count_ID, case when CC=1...

Binomial Test in SAS and R - Different Results

Image
Clash Royale CLAN TAG #URR8PPP Binomial Test in SAS and R - Different Results I need to replicate a binomial test from R to SAS but I'm obtaining different results (or maybe I am misinterpreting the SAS results). In order to explain my problem in an easy way, I will use data from this wikipedia example because it provides the final solution; Suppose you want to calculate the probability of obtaining 51 or more 6s in a sample of 235 roll of a fair die with 6 faces, so that the true probability of rolling a 6 on each trial is 1/6. The final solution should be 0.02654 . In R, the code to do is the following: binom.test(51,235,(1/6),alternative = "greater") and the obtained results are: Exact binomial test data: 51 and 235 number of successes = 51, number of trials = 235, p-value = 0.02654 alternative hypothesis: true probability of success is greater than 0.1666667 95 percent confidence interval: 0.1735253 1.0000000 sample estimates: probability of success ...