I have a bunch of csv files that I imported into SAS but now have edit the contents and wonder if it would be easier in SAS or prior to sas.
Essentially, in one of my character/string fields (length=75), I need to find every instance of say xxxxx (the tricky part is it may be anywhere in the string)and replace the entire string with yyyy.
Could I do something like this in SAS? I think I could do it with a programming language like delphi or vb but can SAS do this? I would save me a lot of backtracking! Any help greatly appreciated!
This is not an ODS question, but is one for Tech Support (or some research in the SAS documentation). This is absolutely something you can do with the SAS programming language and a data step progam. To point you in the right direction, you would use different SAS functions to find the string (like INDEX or the PRX functions) and then also use SAS functions to replace the string...this would happen while the data was still in SAS and before you created your CSV files from the modified data.
Sorry for posting to the wrong forum. I expected that including the word 'Base' in the forum title included discussions on base sas. I assumed incorrectly. Which forum would be the correct one - the enterprise forum?
I was thinking something more like this (since the data is currently in a sas table now, I could go back to the csv - but would rather fix it here, now that I have it in sas)...
if drag1 eq 'twinkle'
or drag1 eq 'twinky'
or drag1 eq 'twinkles'
then do drag1 = 'whatever';end;
Essentially ... I want to find any occurance -like-
?twink? and replace the entire string with 'whatever'.
I have been reading about regular expressions, not sure if that will help. Also read something on a command called 'proc sql ... like' '%twink%'. This seems like it is close but am not sure how to imbed that into the above which I have tested and works but only on those exact values and I want to broaden the scope.
You're right -- this is not appropriate for the ODS forum. However, a quick demonstration of the colon ( operator shows how to change things beginning with "twink" can be changed to "whatever."
input drag1 $char20. ;
length drag2 $ 20 ;
if drag1 =: "twink" then
drag2 = 'whatever';
else drag2 = drag1;
title "Case Counts";
proc print data = twinkdata2;
var drag1 drag2;
In my previous reply to Sergio, I tried to write the punctuation mark, : (colon), but since I had a parenthesis next to it, it was turned into a smiley face. I like smiles as much as anyone, but I'm not sure it's a good idea for software to assume I mean a smiley face when I mean a colon. While I am here, I just would like to share with Sergio that I think he needs to seek out some beginners' help, and keep an open mind to learning, and accept that he will have to do a lot of work to become comfortable with a huge system. There are classes and on-line training. Also SAS-L people are very nice about answering newbie questions. He should the problem very clear, not change it, thinking it must be simplified.
You are right, SAS is huge - it is an enterprise system (and this is my first enterprise job) with so many different ways to do things things (embedded PHP or Proc SQl ...). It's very confusing just finding out how to phrase the question or use the right verbage in the help file to find a starting place.
I understand that the vast majority of the power of sas is in the language and I am trying to learn the basics from on-hand examples, web sites and here. I am willing to put in the work just expect a few scream of frustration now and then.
I am attempting to decipher your last post ... I think I get what you are suggesting!
Sergio had trouble deciphering my post, I think, because I left out "make the" in:
"Also SAS-L people are very nice about answering newbie questions. He should the make the problem very clear, not change it, thinking it must be simplified."
By "simplified" I meant changing a variable like Diagnosis, which has millions of values, to gender because gender has only two. That simplification makes the person who would like to help get off on the wrong track.
On SAS-L you can ask questions about any SAS-related topic, not just the topics of the forums on Support.SAS.com. The address is: http://www.listserv.uga.edu/archives/sas-l.html