Monday, 15 August 2011

Permissions

"There are no personal problems which cannot be solved through suitable application of high explosives."


Sometimes other people want to use the data sets you create. Sure they can read em' but what if they need to edit them too? The following code will allow you to change the permissions of your data sets within SAS:


%let PERMIS = 777;
%let extpath = /sasusers/mark/sasuser.v91;
%let dataset = edit_me;

filename chmod pipe "chmod &PERMIS %trim(&extpath)/&dataset..sas7bdat";

data _null_;
   file chmod;
run; 



note: the data set name specified must be lowercase or else it wont work. You could use the %lower statement to do this automatically.

Chmod changes the permissions of the data set in the library specified. How does it work?

777 is an octal. It refers to a permission configuration that allows absolutely anyone to read or write to the files specified in 'dataset'. The first number refers to the user, the second refers to your group and the third number refers to everyone else.

The values and their meanings can be seen here:
http://en.wikipedia.org/wiki/Chmod under 'numerical permissions'

This is great to use when SAS annoyingly reverts permission to read only whenever you update a file.  If only it was this easy with women!

Saturday, 6 August 2011

Week Beginning and End

So you've been asked to compare the week on week changes in data, no problem!!......Except the data set you have only has the data per individual day.

If only there was a way to convert the individual dates to their corresponding weekdate! As you've probably guessed by now with SAS their is always a solution, in this case it's the INTNX function.

(INTNX('week.2', date_variable, 0, 'beginning'))

Creating a new column and setting it equal to the above function converts a date variable to a weekdate. Each weekdate begins on a Monday however this can easily be changed by changing the integer following 'week.2' E.g. Changing this to 'week.1' will bring back weekdates starting from Sunday.

The second argument in the function is where your date variable goes, however what is even more interesting is what the third and fourth argument allow you to do. If the third argument is changed from 0 to 1 instead, SAS will offset the weekdate by one week, e.g. if the start of the week is 25JUL2011, SAS will shift this to 01AUG2011 instead. This can be extremely useful at times.

The fourth argument specifies whether you want your weekdate to correspond to the beginning of the week or the end of the week. This can be achieved by changing 'beginning' to 'end'.

Problem Solved!