Tuesday, 20 October 2015
Monday, 19 October 2015
Friday, 16 October 2015
Data Step Tip: COMPBL Function
To take extra blanks out of a variable
(character), use the COMPBL function.
Example:
BIGNAME="MARY JANE SMITH"
SMALLER=COMPBL(BIGNAME);
Resulting in:
"MARY JANE SMITH"
Wednesday, 14 October 2015
Data Step Tip: Alignment Option
Analignment specification can be
coded in the PUT statement.
Code-L,-C,or-R after the format.
Example:
124 DATA _NULL_;
125 SET NAMES;
126 PUT @1 NAME $30. -C;
127 RUN;
KATIE
TERESA
STEVE
ANN
NOTE: There were 4
observations read from the data set WORK.NAMES.
Tuesday, 13 October 2015
Data Step Tip: Trailing @ For Efficiency
Use the trailing "@" with input statements to avoid
inputting records you wish to eliminate.
Instead of:
DATA MIDWEST;
INFILE ACCOUNTS;
INPUT @1 NAME $19.
@20 STATE $2.
@24 ACCTNBR $10.
@35 BALANCE 8.;
IF STATE IN ('WI','MN','IA');
RUN;
Better:
DATA MIDWEST;
INFILE ACCOUNTS;
INPUT @20 STATE $2. @;
IF STATE IN ('WI','MN','IA') THEN
INPUT @1 NAME $19.
@24 ACCTNBR $10.
@35 BALANCE 8.;
RUN;
• More Efficient
• Different Layouts in One File
Data Step Tip: Input @ ‘TEXT’
Using INPUT @ ' text' positions the input pointer directly
after the word 'text'.
DATA NAMES;
LENGTH NAME CITY $10 ;
INPUT @1 NAME @ 'CITY=' CITY AGE ;
DATALINES;
ABC CITY=BGLR 25
DEFGH CITY=HYD 30
IJKLMNO CITY=BGLR 28
PQRS CITY=HYD 26
;
RUN;
PROC PRINT DATA=NAMES;
RUN;;
output
Obs NAME CITY AGE
1 ABC BGLR 25
2 DEFGH HYD 30
3 IJKLMNO
BGLR 28
4 PQRS HYD 26
If the text is not found, the pointer will go to a new line
DATA NAMES;
LENGTH NAME CITY $10 ;
INPUT @1 NAME @ 'CITY=' CITY AGE ;
DATALINES;
ABC CITY=BGLR 25
DEFGH CITY=HYD 30
IJKLMNO BGLR 28
PQRS CITY=HYD 26
;
;
RUN;
PROC PRINT DATA=NAMES;
RUN;
output
Obs NAME CITY AGE
1 ABC BGLR 25
2 DEFGH HYD 30
3 PQRS HYD 26
in above example IJKLMNO is missing because the string CITY=
not found,so the pointer will go to a new line.
PC SAS SHORTCUTS
When you are working on PC SAS there are many helpful keyboard shortcuts available at your disposal. For example when you need to comment or un-comment blocks of code, you can save time by using the shortcut instead of typing it all yourself. Or when you are trying to find the matching pair in a set of brackets, simply using the shortcut means that you will not need to spend the time searching yourself.
These actions can be performed with ease by pressing a few buttons on the keyboard. The following table shows some of the shortcuts available to use:
Action
|
Keyboard Shortcut
|
Convert highlighted text to upper case
|
Ctrl Shift U
|
Convert highlighted text to lower case
|
Ctrl Shift L
|
Comment highlighted text
|
Ctrl /
|
Uncomment highlighted text
|
Ctrl Shift /
|
Collapse all sections of code
|
Ctrl Alt – (on number pad)
|
Expand all sections of code
|
Ctrl Alt + (on number pad)
|
Move cursor to matching bracket
|
Ctrl (
|
Move cursor to matching DO or END statement
|
Alt [
|
The full list of available shortcuts can be accessed through the menu:
Tools -> Options -> Enhanced Editor Keys
This will show a list of all commands that have a keyboard shortcut assigned to them, along with a brief description of what the command will do.
Tools -> Options -> Enhanced Editor Keys
This will show a list of all commands that have a keyboard shortcut assigned to them, along with a brief description of what the command will do.
- Convert highlighted text to opposite case
- Insert current date and time
- Delete line
- Repeat the current line
- Remove trailing white space from end of lines
The Assign keys… button can be used to set a shortcut or to change an existing shortcut.
Personally I find switching text to upper/lower case and commenting/un-commenting code to be especially useful and a good time saver.
CONCLUSION
These tips are all easy to learn, quick to use and great to share with other programmers. I would recommend trying these out to see if they can help you in your day to daySAS Programming
For More Click here
Subscribe to:
Posts (Atom)

