Wednesday, December 15, 2010

Find out start and end date of a week

-
data _null_;
*The intnx function can be used to find out the end date of a week (when the user is in the middle of the week);
start=intnx('week',today(),1)-1;
*Then user can then apply the below code to fetch another 12 weeks of data from this weekend date;
end=(start+7*12);
call symput('start_dt',put(start,date9.));
call symput('end_dt ',put(end,date9.));
run;
%put &start_dt &end_dt;

*In a same way the user can find out a start date of a week;
example=intnx('week',today(),0);
-
More: http://www2.sas.com/proceedings/sugi30/255-30.pdf
-

Friday, December 3, 2010

Change the font "of all post"

-
Go to Edit HTML and find "post-body" to embed this code:

.post-body {
position: relative;
font-family: Trebuchet MS !important;
}

Performance tuning while working with large datasets


1. WHERE to subset data
2. KEEP / DROP to reduce cpu time
3. LENGTH to reduce variable size
4. CHARACTER variables need to be created as much as possible
5. IF-THEN/ELSE to improve efficiency
6. MACROS for redundant code
7. PROC SORT only when needed
8. PROC SQL to reduce the number of steps
9. INDEX to read large datasets
10. COPY to copy dataset with index
11. COMPRESS to reduce number of bytes
12. DATA _NULL_ for processing null datasets
13. PROC APPEND instead of set
14. PROCs with CLASS statement need to be used
15. SASFILE to reduces I/O processing
16. STORED PROGRAM FACILITY for complex data steps
17. BUFSIZE for the size of the input/output buffers
18. REUSE for whether free space is reused
19. POINTOBS to randomly access by an observation number
20. NOMACRO to conserve memory
21. KILL unwanted datasets
22. FORMAT/ INFORMAT instead of if then else (for logics)
23. VIEWS to create virtual tables
24. SAS FUNCTIONS to perform common tasks
25. COMBINE steps to reduce number of DATA and or PROC steps

Wednesday, September 8, 2010

Append & Force

-
The procedure append is recommended when the dataset is being overwritten. This helps the user concatenate large number of datasets.
-
Syntax:
-
proc append base=SASHELP.dummy data=WORK.dummy force;
run;
-
The force option displayed here is used to forcibly append the dataset (while encountering differing attributes for the same variable).
-

Wednesday, August 4, 2010

Check for the existence of a dataset

-
The exist function checks for the existence of a dataset.
-
options mprint mlogic symbolgen;
%macro test;
%if %sysfunc(exist(work.dummy))=0 %then %do;
%goto quit;
%end;
%else %do;
proc sql; select count(distinct pt) into: tst from dummy;
run;
%put &tst;
%end;
%quit:
%mend;
-
%test;
-

Kill your datasets


This code will help the user kill the temporary datasets in work library.

proc datasets library=work kill;
run;

Monday, July 26, 2010

FAQs


  1. List out different ways to delete duplicates?
  2. What are the different procs that you have used so far?
  3. Difference between nodup and nodupkey?
  4. How do you get unique observations?
  5. List out different functions that you have used inside a macro?
  6. Tell me about the options that you have used in proc compare & proc report
  7. Can you write down the syntax for proc means or proc freq?
  8. What is the use of multilabel option in proc format?
  9. Brief me about the last project that you have worked on?
  10. What was the interesting technical issue that you have come across & how did you solve it?
  11. Why are you looking for a change?
  12. How do you rate yourself in macro?
  13. Compare merge and proc sql joins?
  14. How do you avoid merge by values?
  15. What is the advantage of using merge over proc sql?
  16. Which is efficient if or where condition? Why?
  17. What are the different ways to create a macro variable?
  18. What is the scope of global and local macro variable?
  19. What are the different items that you will look for in a log?
  20. Difference between format and informat?
  21. What is the use of data _null_?
  22. How do you write a code to see 'only the duplicate observations'?
  23. What is PDV?
  24. List out some automatic macro variables in sas?
  25. What is the result of using two set statement?

Sunday, July 25, 2010

Double Dash


Usually to keep a set of variables with same prefix we use “-“

For example:

COL1 COL2 COL3 COL4 COL5 COL6 COL7

To keep the above variables, we use (keep COL1 - COL7;)

but what if the variables does not have same prefix?

Yes, there is another way to keep the variables even when they do not have same prefix!

“--“ can be used to keep the variables in the order in which they occur in a dataset.

data dummy;
input a b1 b2 c;
datalines;
1 2 3 4
1 2 3 4
1 2 3 4
1 2 3 4
;
run;

data dummy1;
set dummy;
keep a -- b2;
run;

More:
http://studysas.blogspot.com/2009/07/even-you-can-use-hash-and-double-dash.html