Wednesday, July 21, 2010

Script to remove the subversion folder from project directory

Many a times we would want to remove the subversion folders which are present in the project directory for various reasons. (Eg: Copy the structure to another drive, zip it and mail it, etc..). The subversion folders are present in every directory (Eg: .svn, .cvs, etc...).

This script, when executed in windows command mode, removes all the .cvs from the directory structure.

for /d /r . %d in (.cvs) do @if exist "%d" rd /s/q "%d"

Replace a String in Unix

Now that we know how to find a string in a list of files in the home directory, we may also want to replace the string with something else..

Eg: Replacing a password in all the files as and when it is getting changed.

The command to do this is:

find . -type f -name "*.c" -print | xargs perl -i -pe 's/MYOLDPASSWORD/MYNEWPASSWORD/g'

Tuesday, July 20, 2010

Find a String in UNIX

We've become so much addicted to find/search functionality these days that I tend to look out for Ctrl+F button when I want to find something on a hard bound book as well!!

I had a requirement where I had to search for all the files in my home directory recursively which contained my db2 password because I wanted to change my password in them. I came across this shell command which I found pretty useful:

find . -type f -name "*.*" -exec grep -l "MYDB2PASSWORD" '{}' \;

It just searches through your home directory for a file (type -f) with any name (-name "*.*"). If you are sure of the type of the file you would be interested in then you can also specify it in the -name option (Eg: -name "*.c" for all C programs, etc).

-exec allows us to execute any command in Unix. Here I'm using the Grep command to search for the text MYDB2PASSWORD.

Friday, July 16, 2010

Got dating problems? Use ANYDATE...

Many a times we might come across a situation where we would not be able to determine the informat of the date or datetime variable that needs to be read into the SAS dataset. Or me may at times fail to remember the informat name for a particular date informat.

To address these problems, SAS has come up with a common informat for reading the dates for all types of formats - ANYDTDTEw.

See the example below:

Data dates;
Input cdate $22.;
Cards;
16-apr-07
01-02-07
2007-05-06
02-jun-07
13-sep-2007
01JAN2009 14:30:08.5
;
Run;


/* Convert them to required date format using AnydtdteW */

Data Convert;
Set dates;
Date = Input (cdate, ANYDTDTE21.);
Format date date9.;
Run;

The contents of the dataset would be as shown below:

16APR2007
02JAN2007
06MAY2007
02JUN2007
13SEP2007
01JAN2009

However, if we were to have a date being represented as "02/03/04", then it could be quite confusion for us as well as the SAS compiler to know the exact date informat that is to be read in. To overcome this problem, we use the SAS System option - datestyle.

The possible set of values for the datestyle option are: MDY MYD YMD YDM DMY DYM LOCALE.

See the below example to understand the datestyle option clearly:

option datestyle=dmy;

data test;
format dt date9.;
input dt anydtdte10.;
cards;
02/03/04
;
run;

/*output = 02MAR2004 */

option datestyle=ymd;

data test;
format dt date9.;
input dt anydtdte10.;
cards;
02/03/04
;
run;

/* output = 04MAR2002 */

option datestyle=myd;

data test;
format dt date9.;
input dt anydtdte10.;
cards;
02/03/04
;
run;

/* output = 04FEB2003 */

Thursday, July 15, 2010

Adding Abbreviation in SAS

I am a bad typer. And I have a short term memory loss. Remembering the syntax, typing a lot of code (especially the repeating ones)... Na... Not my cup of tea..

SAS Enterprise Guide (4.1 onwards) has come up with a one shot solution for people suffering from my kind of syndrome - Adding Abbreviation.

Here is how you can go about it:
  • Open a new code window in SAS EG
  • Go to Code -> Add Abbreviation
  • You get a window where you can add the abbreviation and the text which needs to be substituted for the Abbreviation used. See the example below:

Here, I have a requirement of using my passthrough syntax every now and then and I tend to forget the syntax, password and sometimes even my user name :-)

So.. I use the Abbreaviation 'Pr' and enter the text (rather Copy & Paste) as shown in the above image. Click Ok.

Next time you would want to enter the code, just type Pr and you get a prompt (Yes... à la Visual Studio IDE)

Now, hit the tab or press Enter and you have the code on your Screen!

You can also edit your Abbreviation by going to Code -> Editor Macros -> Macros. Select the required macros (if any) and Click on Edit.

Collateral damage (Control)

Indexed SAS datasets are at times vulnerable to getting damaged. Especially when you update an indexed dataset. To save this damage, SAS has come up with these options which repairs the dataset and gets back the data to its original form.. (trust me.. It once saved my life! Phew!!!!)

Check the below link for the damage control. I tried the option DLDMGACTION=NOINDEX. This was because my data step had completed and i was not able to access the data. There are many other senarios explained which might be handy sometimes...

http://support.sas.com/documentation/cdl/en/lrcon/62955/HTML/default/viewer.htm#/documentation/cdl/en/lrcon/62955/HTML/default/a001043251.htm

Wednesday, July 14, 2010

Hello World!

Yippie!! I make my entry in Blogspot!!

Watch out for more posts in days to come....

Monday, July 12, 2010

Doing it in Style!!!

Have you ever wondered how to format your output in the style you want? How to get your favorite header colors, your favorite fonts and maybe even a background image(???) to your report you generate in SAS?

Well, it can all be done in SAS Enterprise Guide using your Style manager. Alternatively you can include your favorite stylesheet css file ( you get a lot of them on google.. Or you can create one on your won...) in your SAS EG..

Here is how you can go about it...

Go to Tools -> Style Manager. Here you find a variety of built-in styles on the left pane. If you see the url column in the Style List, you can notice that these are nothing but the pre defined css provided by the SAS Enterprise Guide.



You can choose any of the predefined styles here. If you would want to have a new style of your own.. then you can do the following:

  • Click on Add button
  • Select - Add new based on existing style option
  • Select minimal in the dropdown menu
  • Give name to your style
  • Click on Ok button. You can see that a new css file has been created your home directory
  • Now go to the Edit option
  • You can select the Active element in the left bottom corner and chosee the element to which you need to apply the style. Eg: Choose Title and Note Corner and apply the color you want to add, etc.
  • You also have the option to add a new element by clicking on Add element. Eg: Click on the Header available in the Preview window, and click on Add Element, give a suitable name and then add your customization.
  • You can similarly customize your table borders, add an image, change fonts, add a custom footnote, etc.

Lastly, if you still are not satisfied with any of these features, you can always download a css from various sites and add them into the style manager by choosing the 'Add new external style' option.

So... The ground is open for you guys to play around and experiment.. Its a neat wizard which allows you to customize your report to a fairly good extent..