« December 2012 | Main | February 2013 »

January 29, 2013

Debugging in SAS

I'm working through some tutorials and this seems to be an important topic.


putlog _all_; *prints the current pdv (working data row) to the log;

the _ERROR_ variable increments to one if a syntax error occurs. You can use conditional logic to output variable information to the log.

putlog 'WARNING: blah blah'; * will colorcode the output


Debugging
data customers /debug; *will enter debug mode;

- doesn't work with SAS Enterprise Guide

Step - goes to nex step
Watch or W [variable] - auto-print variable value when it changes
Deletewatch or DW [variable]
Examine or E [variable] - print a variable value
$ examine varible $quote7. - print variable within quotes and up to 7 characters
List or L [_All_ Files Break INFILES Datasets WATCH] - print all items within the specified option
Set [variable] = [value] - change a variable value

List or L


set [dataset] END=last; * when the data step cycles through the last observation of the dataset 'last' will be set to one. Conditionals can be added to do something special upon reaching the last row;

Posted by kkwaiser at 11:54 AM | Comments (0)

January 28, 2013

Variable Lists

numbered range
total = sum(of Qtr1-Qtr4); *will hit Qtr2, Qtr3, etc.;

name range
specify columns in between those specified
total = sum(of Qtr1--fourth);
total = sum(of Qtr1-numeric-fourth); *only 'numeric' (can use 'character' too) between the variables specified;

name prefix
all columns beginning with specified string

total = sum(of Tot:);

Others

Total = sum(of _All_); *Can also use _Numeric_ or _Character_;

Posted by kkwaiser at 04:39 PM | Comments (0)

SAS FAQ #31346987234: The DSD Infile option

Using the DSD option as part of an infile statement will cause sas to ignore "delimiters" that may be found within a quoted text string.

Two consecutive delimiters will lead to a missing value with DSD.

A source.

Posted by kkwaiser at 01:25 PM | Comments (0)

January 25, 2013

Read variables or datasets with names containing spaces

SAS hates spaces - which I am fine with - but sometimes a variable or dataset exists with spaces in it's name. To get around this put the name/variable into quotes followed by an 'n'.

proc contents data=work.'poorly named dataset'n;
run;

BAM

Posted by kkwaiser at 02:43 PM | Comments (0)

January 24, 2013

How to install Drush on ITS servers

How to install Drush on ITS servers

--------------------
See http://drupal.org/project/drush README.txt
--------------------

1. SSH into ITS servers via the PHP-enabled host
$ ssh [uniqname]@[email webmaster@umich.edu for the hostname]

2. Go to your group or personal AFS space to install Drush. This document uses the personal space.
$ cd /afs/umich.edu/user/[]/[]/[uniqname]/Private

3. Download and unpack the latest, appropriate version of Drush given your Drupal install. Drush5 works for Drupal 6 and Drupal 7
$ wget http://ftp.drupal.org/files/projects/drush-7.x-5.8.tar.gz
$ tar -xzf drush-7.x-5.8.tar.gz
$ ls drush

4. Make the 'drush' command executable
- Note this diverges from the Drush README considerably because the "export PATH=" command is "bash" (Bourne Again SHell) syntax.
and the default shell on the PHP-enable host is the C-shell ("csh").

a) Add this command to you .login file
$ cd ~
$ nano .login
At bottom of file (where is specifies for customizations) add

set path=($path /afs/umich.edu/user/[]/[]/[uniqName]/Private/drush )

This command could also go into your ~/.cshrc file

b) Alternatively, if you already have a "~/bin/" directory, you could use the "ln -s"
command to create a symbolic file link (sym-link) in there for "drush"
with:

ln -s ~/Private/drush/drush ~/bin/drush

5. Test that Drush works

$ cd /path/to/drupal/install
$ drush help

Posted by kkwaiser at 02:22 PM | Comments (0)

Install or Move CKFinder Libraries so sites/all/libraries

$ sudo drush up

CKeditor is broken. Fix it.

1) How to install CKEditor Library

$ cd sites/all
$ mkdir libraries
$ wget http://download.cksource.com/CKEditor/CKEditor/CKEditor%204.0.1/ckeditor_4.0.1_standard.tar.gz
$ sudo tar -xzf ckeditor_4.0.1_standard.tar.gz

Probably some other steps here...

2) How to install CKFinder

$ sudo wget http://download.cksource.com/CKFinder/CKFinder%20for%20PHP/2.3.1/ckfinder_php_2.3.1.tar.gz
$ sudo tar -xzf ckfinder_php_2.3.1.tar.gz


Edit ckfinder/config.php

Comment out the entire "function CheckAuthentication(){ blah}" function

Add this require_once line below the $baseDir variable. Note, I do not know why it goes up so many directories but it works:

$baseDir = resolveUrl($baseUrl);
require_once '../../../../../modules/ckeditor/includes/filemanager.config.php';

Add/remove/modify the directories that will appear in the CKFinder window when users upload. This is found in the $config['ResourceType'][] = Array() arrays.

Edit the CKEditor profiles (admin/config/content/ckeditor)
- CKEditor Global Settings- make sure the paths to CKFinder and CKEditor point to the sites/all/libraries directory.

- For the Editor Profiles, make sure CKFinder is selected for file management options

Edit permissions (admin/people/permissions)
- Make sure the appropriate roles have access to CKEditor and CKFinder
- Note, if CKFinder access does not appear on this page then the library likely has not been located correctly.

Posted by kkwaiser at 10:17 AM | Comments (0)

January 23, 2013

CKFinder error bookmark

This link may come in handy later.

Posted by kkwaiser at 02:09 PM | Comments (0)

Changing the default upload directory for CKFinder

I inherited a site to maintain (and develop a bit) and it uses CKFinder with CKEditor to allow content managers to upload files via the WYIWYG. One problem with the default settings was the file url that was produced after upload. The file path took the form http://mysite.edu/sites/default/files/files/readme.pdf.

To get rid of the extraneous 'files' you need to go into sites/all/modules/ckeditor/ckfinder/config.php and find the section where $config['ResourceType'] statements occur. The URL should have only the $baseURL whereas the site I am working on had $baseUrl . 'files' .

Fin

Posted by kkwaiser at 11:37 AM | Comments (0)

Change site from sites/default to site/customDirectory

h/t to Eric London for another another useful post.

1. Install and patch the Site Directory Migrate module.

$ cd sites/all/modules/sitedir_migrate
$ wget http://drupal.org/files/1568538-d7_fix-2.patch
$ git apply 1568538-d7_fix-2.patch

- enable submodules as appropriate

2. Visit admin/config/system/sitedir_migrate and set From and To values accordingly. Example From:default To:newDir > Save Configuration

3. Create newDir in sites folder
$ sudo mkdir sites/newDir

4. Update file systems settings admin/config/media/file-system. Example: sites/newDir/files > Save

5. Copy file directory and settings.php over to newDir
$ cd sites
$ sudo cp -rfp default/settings.php newDir/
$ sudo cp -rfp default/files/ newDir/

6. Clear site cache
$ drush cc

Posted by kkwaiser at 10:20 AM | Comments (0)

January 18, 2013

Using Patch and Diff

This link has useful instructions.

$ sudo diff -ruBN registration_original.php registration_withPhone.php > ~/Desktop/registration.diff

$ sudo patch -p0 < registration.diff
- this command will make original match _withPhone

$ sudo patch -p0 -R < path/file.patch
- reverse a patch; see drupal.org for more.

Git directions:

Install Git
$sudo apt-get install git-core

$ cd to directory containing files to patch (unless header of patch lists directories below that)

$ sudo git apply [path/to/git_patch]

Posted by kkwaiser at 11:55 AM | Comments (0)

Create random number string in SAS

Adapted code from here

%let NObs = 52;

data test_psid(keep=psid);
call streaminit(123); /* random num generator seed*/
Min = 100000; Max = 999999; /*range of random number*/
do i = 1 to &NObs;
psid = min + floor((1+Max-Min)*rand("Uniform")); /* uniform integer in Min..Max */
output;
end;
run;

Posted by kkwaiser at 10:08 AM | Comments (0)

January 07, 2013

Importing files in SAS

This will import a comma delimited file. Note that input is required and can be used to specify only certain variables that should be part of the dataset.


DATA work.test3;
infile 'J:\blaise_sample_files\mixed_mode\5_sample_set\sample_other.csv' dlm=',';
input var1 var2;
run;

This SAS pdf has more.

There is also a PROC IMPORT statement but I'm not sure when you would use one approach over the other.

PROC IMPORT OUT=work.test
			FILE = "J:\blaise_sample_files\mixed_mode\5_sample_set\sample_other.csv"
			DBMS = CSV REPLACE;
	GETNAMES = YES;
	DATAROW = 2;
RUN;

Posted by kkwaiser at 12:55 PM | Comments (0)

Where statements in the DATA step


Select a subset of data set that contains only NULLS:

data work.testnulls;
set work.test;
where PushStringToMainIw = ' ';
drop DOB TIMEZONE;
RUN;

Select subset of data where a given column contains a value. This gets into some regex for SAS

- the percent sign (%) replaces any number of characters
- the underscore (_) replaces one character


data work.testnulls;
set work.test;
where PushStringToMainIw LIKE '10-1xxx-003%' ;
RUN;

Posted by kkwaiser at 11:44 AM | Comments (0)

January 04, 2013

_n_ variable in SAS

Creating a post on this because the interwebs appear to be a bit crossed.

One source indicates

The automatic variable _n_ represents the observation numbers.

While another indicates

Each time the DATA step loops past the DATA statement, the variable _N_ increments by 1. The value of _N_ represents the number of times the DATA step has iterated.

I suppose these are equivalent statements if the data step iterates for every observation in the data file.

Posted by kkwaiser at 04:09 PM | Comments (0)

Useful shortcut commands in SAS 9.x

In lieu of hotkeys to toggle between SAS windows I am going to try using the Command prompt (with command shortcut set to ctrl+j).

A somewhat complete list of commands from the SAS people.

Commands to open a new Enhanced Editor or to toggle to the current Editor.

WPGM to go back to original enhanced editor window
WEDIT to create a new enhanced editor window
LOG
OUT

SOURCE

Posted by kkwaiser at 10:11 AM | Comments (0)

January 01, 2013

About the UM Biological Station portion of this blog

EDIT: I am now working with the Institute for Social Research. Posts date prior to this one are relevant to the UMBS. Posts created after this are relevant to ISR.

This is a work blog with three primary aims. They are, in decreasing order of importance, 1) preserve a record of my activities for future University of Michigan Biological Station information managers and administrators, 2) help me to avoid that all too annoying remark, "How did I do that last time?!" and 3) provide useful knowledge to random corners of the web.

The vast majority of posts are Drupal related due to the fact that the open-source content management system underlies our information management system, the Research Gateway, and this has been the primary need of UMBS to date. However, posts on other topics do occur and, as the Research Gateway is firmly into v1.0 territory, they will hopefully become more common.

If you have questions or comments related to posts on this blog you can leave them with the actual post or, if you do not want to create a UM identity, you can email me.

Posted by kkwaiser at 12:54 PM | Comments (0)