12-23-2020
ginak
Quartz | Level 8
Member since
03-10-2012
- 81 Posts
- 43 Likes Given
- 0 Solutions
- 1 Likes Received
-
Latest posts by ginak
Subject Views Posted 979 12-23-2020 04:02 AM 1478 05-12-2020 06:41 PM 1484 05-12-2020 06:21 PM 1540 05-12-2020 05:03 PM 15136 09-05-2018 05:15 PM 15158 09-05-2018 03:33 PM 15174 09-05-2018 03:10 PM 2085 08-17-2018 12:53 PM 2133 08-16-2018 09:45 PM 5933 05-23-2018 12:55 PM -
Activity Feed for ginak
- Got a Like for Adding Chi-Square P-values to tables using PROC TABULATE. 07-08-2022 10:39 AM
- Posted How to implement different formulas in long format data that differ depending on previous value on SAS Programming. 12-23-2020 04:02 AM
- Tagged How to implement different formulas in long format data that differ depending on previous value on SAS Programming. 12-23-2020 04:02 AM
- Tagged How to implement different formulas in long format data that differ depending on previous value on SAS Programming. 12-23-2020 04:02 AM
- Tagged How to implement different formulas in long format data that differ depending on previous value on SAS Programming. 12-23-2020 04:02 AM
- Tagged How to implement different formulas in long format data that differ depending on previous value on SAS Programming. 12-23-2020 04:02 AM
- Liked Re: How to replace characters in a string that follow certain characters? for ChrisNZ. 05-12-2020 06:42 PM
- Posted Re: How to replace characters in a string that follow certain characters? on SAS Programming. 05-12-2020 06:41 PM
- Posted Re: How to replace characters in a string that follow certain characters? on SAS Programming. 05-12-2020 06:21 PM
- Posted How to replace characters in a string that follow certain characters? on SAS Programming. 05-12-2020 05:03 PM
- Tagged How to replace characters in a string that follow certain characters? on SAS Programming. 05-12-2020 05:03 PM
- Tagged How to replace characters in a string that follow certain characters? on SAS Programming. 05-12-2020 05:03 PM
- Tagged How to replace characters in a string that follow certain characters? on SAS Programming. 05-12-2020 05:03 PM
- Tagged How to replace characters in a string that follow certain characters? on SAS Programming. 05-12-2020 05:03 PM
- Tagged How to replace characters in a string that follow certain characters? on SAS Programming. 05-12-2020 05:03 PM
- Tagged How to replace characters in a string that follow certain characters? on SAS Programming. 05-12-2020 05:03 PM
- Liked Re: Total Sum vertically for LinusH. 09-06-2018 11:33 PM
- Posted Re: Importing a .CSV file from R with NA's as missing on SAS Programming. 09-05-2018 05:15 PM
- Liked Re: Importing a .CSV file from R with NA's as missing for Tom. 09-05-2018 03:50 PM
- Liked Re: Importing a .CSV file from R with NA's as missing for Tom. 09-05-2018 03:50 PM
-
Posts I Liked
Subject Likes Author Latest Post 1 4 2 4 3 -
My Liked Posts
Subject Likes Posted 1 04-20-2012 05:25 AM
07-05-2017
10:38 PM
YES!! This is correct! and it worked for me with no errors. Thank you so much 🙂 After doing this, I just did a simple merge in a data step and it worked without giving me the 'the variables are not sorted in the proper order' error. Thanks!!!
... View more
07-05-2017
08:50 PM
Hello,
I have two datasets I'd like to merge. The first one contains odds ratios and confidence intervals, the second contains the corresponding p-values. So each variable has a class statment. E.g., Race6 has 5 levels (asian vs. white, american indian vs. white, etc.). There is also an intercept that I'd like at the top. The problem is, if I sort the data by effect and then classvalue, that it'll put the variables in alphabetical order. But I want them to be sorted by formatted order. So I try to sort them w/ proc sql then merge but it doesn't work (see below), so then I try to merge with a left join (very bottom).
in my have.jpg, you can see the formatted names of 'variable' are in the 'effectz' column. So when SAS sorts, it sorts variable in alphabetical order. I'd like to sort it to have it in effectz's order (keep in mind that effectz = variable, except I put the format on effectz just to show you).
Basically, I want the order of have.jpg, but to add on the corresponding odds ratios from the have_orcl.jpg merged in. How can I do this? I tried it two different ways.
/*This is the have.jpg table. I formatted effect to put it in the order I want, and then tried to sort it by the order of the effectf format and then by classval0*/
proc sql;
create table table3c as
select variable as Effect FORMAT = $effectf.,
classval0,
probtb,
run
from table3b
order by put(effect, $effectf.), Classval0;
quit;
When I do this, I get the following message in the log: "NOTE: The query as specified involves ordering by an item that doesn't appear in its SELECT clause." What does this mean? Why is it doing this? It seems to have worked. But then again, I wouldn't know because it's already in order.
/*Now sort the have_orcl.jpg table.*/ proc sql;
create table table4c as
select effect2 as Effect FORMAT = $effectf.,
classval0,
orcl,
run
from table4b
order by put(Effect, $effectf.), classval0 ;
quit;
When I do this, I get the following message in the log:
"NOTE: The query as specified involves ordering by an item that doesn't appear in its SELECT clause."
Now, I want to merge them:
data comb2 ;
merge table3c table4c;
by Effect classval0;
run;
And I get this error:
ERROR: BY variables are not properly sorted on data set WORK.TABLE3C. Effect=01 Race classval0=6 Other/Multi. probtb=0.8000 Run=1 orcl=1.07 (0.65 - 1.74) FIRST.Effect=0 LAST.Effect=0 FIRST.classval0=1 LAST.classval0=1 _ERROR_=1 _N_=7 NOTE: The SAS System stopped processing this step because of errors.
So my goal was to originally merge, but it didn't work, so I tried sorting by the formatted variables so I could merge and have those in that order. That didn't work. So I tried a SQL join:
proc sql;
create table MERGEd as
select L.*, R.*
from table3c as L
left join table4c R
on L.effect=R.effect
and L.classval0=R.classval0
order by put(effect, $effectf.), classval0;
quit;
I know I'm not supposed to include the ", R.*" and I get this error when doing so:
WARNING: Column named effect is duplicated in a select expression (or a view). Explicit references to
it will be to the first one.
WARNING: Column named classval0 is duplicated in a select expression (or a view). Explicit references
to it will be to the first one.
NOTE: The query as specified involves ordering by an item that doesn't appear in its SELECT clause.
WARNING: Variable Effect already exists on file WORK.MERGED.
WARNING: Variable classval0 already exists on file WORK.MERGED.
WARNING: Variable Run already exists on file WORK.MERGED.
BUT I am not sure how to do it otherwise. If I don't include the ", R.*" then it won't pull in my orcl column (the column with the Odds ratios (Confidence Interval)) from the have_orcl.jpg. But it still works (see GOT.jpg).. I am just not allowed to submit something with an error statement. Help?
I have tried to include my code as reference, and also searched the message boards. That's how I got the last bit of SQL code 🙂 But I'm not sure how to fix the warning sign...
... View more
07-04-2017
07:38 PM
Hello,
I have used proc surveylogistic and ods output to extract information from my analysis so that I may manipulate my output into a nice, clean dataset to print out. However, I'm having trouble extracting string.
I have something like this *see the picture attached called "effect.JPG"*
I want to split that column up into 2, where I have it look like the 2 columns in "effect WANT.JPG"*
How can I do this? I need a combination of substr, index, COMPBL, scan etc. functions and I'm not sure. I was able to get the first column, call it "variable," by doing this:
spaceplace = index(effect, ' '); variable= substr(effect,1,spaceplace);
However, I need help getting the class level name (labeled as "Level of CLASS Variable for 1 Variable" in the effect2 WANT.JPG file). Basically, what I need to do is to extract the string that comes after the first word, first spaces, but is before the "[trailing blanks] vs [string]"
How can I tell sas to give me the word that comes right before the "vs" string? I tried to write out a code for you guys to play around with, but it is not working 100% for me 😞 But maybe you can modify this?
data one; input name $1-100; cards; 'race6 1 Am. Indian vs 7 White' 'race6 2 Asian vs 7 White' 'marital2 1 Single vs 4 Married' 'lengthdeployment 1 Less than 1 month vs 6 I did not deploy in the past 12 months' ;
data two; set one; spaceplace = index(effect, ' '); variable = substr(effect,1,spaceplace);
*The above two lines gave me my variable column and it worked in my main code. Not sure if it'll work here though;
*This is my closest attempt to getting it. but it is still wrong and gives me the vs [text] for some of them:;
vsplace = index(effect, ' vs ');
CLASSNAME3 = COMPBL(strip(substr(effect, spaceplace, vsplace-5))); run; proc print; run;
So in my case, I'd want to have classname3 look like this
1 Am. Indian 2 Asian 1 Single 1 Less than 1 month
I think it'd just be easier to look at my "effect2 want.jpg" to see what I am trying to achieve.
Many thanks for your help. Yes, I have looked through the message boards for similar searches but am still having trouble. I hope you're having a nice 4th of July!
Best, Gina
... View more
07-04-2017
04:00 PM
This worked for me, too! the only problem is that I have many, many variables T_T but thank you for showing me that it can be done! I think my problem then, is that I used the cat statement to add in the blanks instead of manually typing them? Not sure why mine didn't work since it seems like we did the same thing. Oh well. There are better ways to do this anyway, like you said. I have tried ods tagsets and that seemed to help
... View more
07-04-2017
03:54 PM
Hi, yes you are correct. Tagsets seem to do the trick for me. I just need to research on how to use proc report 🙂 Thank you!
... View more
07-04-2017
03:53 PM
Thank you for your help! Yes, I think the style option + tagsets did the trick for me. And I just don't export as a .csv (type of excel file is not as important since I just need it to be in Excel).
... View more
07-04-2017
03:48 PM
Hi,
It is excel. But like one of the other commentors mentioned.. for a .csv it'll happen. I just have to use tagsets
... View more
06-21-2017
09:28 PM
Hi all,
I did a thorough search of the message boards before deciding to finally post because I am still confused. Help! I created a dataset of results in SAS to export to Excel via csv file. However, it removes my trailing blanks. I posted what I want it to look like in SAS, and what it looks like in the excel screenshot. Notice that it also removes the trailing 0 in "0.40"
How can I keep these? I'll paste part of my code. Here, race5 is our "&xvar" and you can see below where I added the leading blanks.
%macro simple(xvar, output); %do i = 1 %to 2; /*%do i = 1 %to %sysfunc(countw(&outcomes));*/ %let tabit = %scan(&outcomes, %eval(&i));
title "I. y= &tabit , x =&xvar";
data comb4 (keep = NOBsUsed NOBsRead Run value effect2 pval count variable classval0 count2 orcl); retain value NOBsUsed NOBsRead effect2 variable classval0 orcl pval count count2 Run; set comb3; length pval 8.; format pval PVALUE6.4; if probtb ne . then pval = probtb; else pval = probfb; LABEL orcl = "OR (95% CI)"; LABEL pval = "p"; else if classval0 ne "Female" and classval0 ne "At least 1 child <18" and classval0 ne "Never deployed" then classval0 = cat(' ',classval0); /********HERE I ADDED IN SOME LEADING BLANKS*******/ if classval0 = "" then pval = .; if classval0 ne "" then Run = .;
put classval0 $char80.; /****I FOUND THIS ON A MESSAGE BOARD AND TRIED IT BUT IT DIDN'T WORK*****/ RUN;
%mend;
... View more
04-20-2017
03:46 PM
Yes, thank you!!
... View more
04-20-2017
03:46 PM
Thank you!! Yes, it was late at night and I tried but wasn't sure what keywords exactly to use 😞 Good advice re formatting w/ a data step. Will note.
... View more
04-20-2017
04:03 AM
Hello!
I have two data sets I want to merge. One is application information, the second is registrations. There are some who registered but did not fill out an application.
Suppose we have:
Application:
ID Name ... (other variables)
1 Bob
2 Bill
3 Judy
4 John
Registration: ID Name ... (other variables)
1 Bob
2 Bill
3 Judy
4 John
5 Jake
6 Jack
I know how to merge them as such:
data merge;
merge application (in=a) registration (in = b);
by ID;
if a and b;
run;
However. I would like SAS to also give me an output dataset of those who were not in both application and registration (i.e., ID's # 5 and 6 - Jake and Jack).
So I'd like code to give me two datasets:
Merge:
ID Name... (other variables from both datasets)
1 Bob
2 Bill
3 Judy
4 John
5 Jake
6 Jack
and remainder:
ID Name ...(other variables)
5 Jake
6 Jack
So it gives me the names of just those two where not in the application dataset as well
How can I do this? I've seen it before, but can't remember how to search it unfortunately.
Thanks!
Best,
Gina
... View more
04-20-2017
01:47 AM
Hello!
I have a variable called CellPhoneNo (cell phone numbers) that I want to look like this: 555-222-3333. This is what most look like:
5552223333
but some people included a 1 so now I also have:
15552223333
My goal is to add a format to change this to
555-222-3333.
How can I do this if some numbers start with a 1? I was thinking of eliminating the "1" and then applying the format. But is there a way to just add a dash in starting from the right, 4 digits in, and then keep going after 3, and then after 1 place in case there is a "1" at the beginning?
Thanks!
Best,
Gina
... View more
11-10-2016
06:12 PM
Hello all!
I am having trouble extracting data and time from these variables (they are all character variables): MemberNameNum DOB ServiceStart
Prinze Jr,Freddie(124A) Dec 21 1951 12:00AM 2014-07-31 00:00:00
Doe,John(100B) Apr 6 1955 12:00AM 2014-05-14 00:00:00
Abdul Jawad, Joe(325A) Apr 21 1941 12:00AM 2015-07-29 00:00:00
What I would like to do is to get it in this format, where the dates and times are numeric SAS dates and times:
Last_name First_name ID DOB_date DOB_time Service_start_date service_start_time
Prinze Jr Freddie 124A 12/21/1951 12:00AM 07/31/2014 00:00:00
Doe John 100B 04/06/1955 12:00AM 05/14/2014 00:00:00
Abdul Jawad Joe 325A 04/21/1941 12:00AM 07/29/2015 00:00:00
I tried playing around with the substring function but was havign trouble. You'll notice that there is no space after the comman in "last,first" but there is one in Joe's after the comma:"Abdul Jawad, Joe" and there is two spaces after April since the date, 6, only is one digit, but for everything else there is one space between the month and the day in DOB. The times are all the same, but it would be nice to have them in case if someone's isn't 12:00AM or 00:00:00. I couldn't find the format for "Month day year" where month is abreviated and year is 4 digits (like what I have). I have been reading through the other postings to see if I could find a solution but alas, have not been able to solve this. Any help would be appreciated 🙂
Thanks,
Gina
... View more
07-29-2016
03:33 PM
Thank you! I think so; but what would go in place of the "??" sorry, I didn't understand haha.
... View more
07-29-2016
03:31 PM
Thank you very much! Yes this would work. The only thing that I wonder is, say, for Diabetes, you can have either '250' or '250.0' through '250.93' In that case, how would you specify? For this line: if ('2500' <=: dx{_n_} <=: '25093') then diabet=1;
... View more