Saturday, March 31, 2012

SAS to FTP files. General code.


This code is basically to use FTP from SAS, i hope you guys can use it at many places.

FTP data from sas to mainframe or any place :
(i use the code to ftp to mainframe , but it works for any other place too)


%let userId=;
%let pwdId=;

%let MVSZoS = MVSIBM.test.a; /* or give a ip address as /*

%let MVSZoS = 10.255.255.1; /* if u have the ip use this */

%let tempfile=c:\test_Ftp.prm; /*this is the input file you want to ftp (on from server)*/

%let out=myid.test.recieve.ftp; /* this is the file name to recieve ftp (on to server)*/

%let scr=c:\ftpparmameters.scr; /* this is a script file, just create a blank empty file on your
server ( from serve) */

filename f "&scr";


data _null_;
file f;
put "open &MVSZoS";
put "&userId";
put "&pwdId";
put 'cd ..';
put "send &tempfile" " &out";
put 'quit';
run;

%macro makework;
data _null_;
infile makework;
input;
put _infile_;
call symput('timestmp',datetime() );
run;
%mend;

%makework;

filename makework pipe "ftp -s:&scr";


This is more or less a general code , just change the parameters in let statements and you make it yours !

Like to hear your comments.


Thanks,
KB

Thursday, March 29, 2012

Using large datasets in SAS ! Append Vs Set / Union.

Guys this is a intelligent tip !
I came across this while dealing with some of the huge dataloads .

Where to use it?! : Whenever adding to a huge dataset .

Code :

A)
PROC DATASETS;
APPEND OUT = membr_a
DATA = membr_b (WHERE=(year=2000));
RUN;

B)
DATA membr_a;
SET membr_a membr_b
(WHERE=(year=2000))

C)
Proc SQl;
create table xxx
select * from membr_a union select * from membr_b ;
quit;


Explanation of code:

A)
OUT --> is the output dataset to which you want to append.
Data --> is the new dataset , which you may want to add to the existing dataset (mentioned in out).

B) & C) --- i won't explain them , too trivial !


Advantage ??

The APPEND function is used to append observations from one dataset to another. Unlike the SET command which reads in all observations from the datasets being concatenated, the APPEND function only reads in the observations from the
dataset being appended. By using the APPEND function over the SET command you will save processing time and work
space

Options: "Force" option is always available when merged dataset are not exactly same !


Thanks,
KB

Some Test Question :SAS/GRAPH

SAS/GRAPH 1: Essentials


What are the components of a SAS data set?
a. row portion and column portion
b. value portion and format portion
c. data portion and descriptor portion
d. variable portion and observation portion


What are the required attributes of a variable?
a. name, type, and length
b. name, type, and format
c. name, label, and length
d. name, label, and format


What is the default justification for a numeric variable in a PROC PRINT report?
a. left-justified
b. right-justified
c. center-justified
d. decimal-justified


By default, when do labels appear in a PROC PRINT report?
a. always
b. only when the labels are permanent
c. only when a LABEL statement is in the PROC PRINT step
d. only when the LABEL option or SPLIT= option is in the PROC PRINT statement


What determines colors and fonts when you send a PROC PRINT report to the ODS HTML destination?
a. the SAS data set
b. an ATTRIBUTE statement
c. ODS COLOR and ODS FONT statements
d. the default ODS style template or the template name specified in the STYLE= option


Which data set option selects variables?
a. COL=
b. VAR=
c. KEEP=
d. SELECT=


Which statement selects observations in a procedure step?
a. IF
b. RETAIN
c. WHERE
d. INCLUDE


What sort sequence does PROC SORT use by default?
a. ascending order
b. descending order
c. numeric variable values in descending order and character values in ascending order
d. numeric variable values in ascending order and character values in descending order


How do you end a SAS/GRAPH device-based procedure, such as PROC GREPLAY, with the correct step boundary so that the procedure terminates processing?
a. run;
b. quit;
c. stop;
d. ods _all_ close;


Which symbol or value must character format names begin with?
a. dollar sign ($)
b. percent sign (%)
c. pound or hash sign (#)
d. character value (a-z or A-Z)


What happens to output from a SAS/GRAPH program if the LISTING destination is closed and no other ODS destinations are open?
a. The SAS/GRAPH output is written to a work file, and no image is displayed in the GRAPH window.
b. SAS opens the HTML destination automatically and sends the SAS/GRAPH output to an ODS HTML output file.
c. No SAS/GRAPH output is created, and the SAS log shows the warning message WARNING: No output destinations active.
d. SAS automatically opens the LISTING destination and displays a note that says NOTE: The LISTING destination was opened for SAS/GRAPH output.


Which is a valid LIBNAME statement?
a. libname 'c:\sasfiles';
b. libname mylib 'c:\sasfiles';
c. libname 'c:\sasfiles' mylib;
d. libname 'c:\sasfiles' libref=mylib;


Consider the following PROC SORT step:
proc sort data=customers;

run;
Which statement completes the step and sorts the observations in descending order by ID and, within ID, in ascending order by LastName?
a. by ID descending LastName;
b. by descending ID LastName;
c. by descending ID ascending LastName;
d. by ID descending LastName ascending;


Which TITLE statement correctly codes the title Fred's Report?
a. title "Fred's Report";
b. title 'Fred' ''s Report';
c. title ' "Fred's Report" ';
d. title allowquote(Fred's Report);


Which option identifies an input SAS data set to a SAS procedure?
a. SET=
b. DATA=
c. INPUT=
d. INFILE=


Which procedure creates bar charts?
a. PROC BARS
b. PROC VBAR
c. PROC GCHART
d. PROC BARCHART


Which statement clears all titles?
a. title;
b. clear titles;
c. clear_titles;
d. title clear all;


Which statement correctly closes the LISTING destination?
a. ods;
b. ods close;
c. ods listing close;
d. ods _listing_ close;


Where can ODS reports be viewed?
a. a browser
b. a word processor
c. the Output window in the windowing environment
d. all of the above


What happens when a DATA step or PROC step contains multiple WHERE statements?
a. Only the first WHERE statement is processed.
b. The WHERE conditions are combined with a logical AND operator.
c. The last WHERE statement replaces previous WHERE statements.
d. A syntax error is displayed in the log, and the program does not execute.

Some Test Question : SAS & ODS

Guys !
its march end , the interview time . So on request i am posting some questions.

Try to solve them and get back to me if you need answers. PM me!

**********************************************************************************



SAS Report Writing Test 1: Using Procedures and ODS


What are the components of a SAS data set?
a. row portion and column portion
b. value portion and format portion
c. data portion and descriptor portion
d. variable portion and observation portion


What are the required attributes of a variable?
a. name, type, and length
b. name, type, and format
c. name, label, and length
d. name, label, and format



What is the default justification for a numeric variable in a PROC PRINT report?
a. left-justified
b. right-justified
c. center-justified
d. decimal-justified


By default, when do labels appear in a PROC PRINT report?
a. always
b. only when they are permanent labels
c. only when a LABEL statement is in the PROC PRINT step
d. only when the LABEL option or SPLIT= option is in the PROC PRINT statement



What determines colors and fonts when you send a PROC PRINT report to the ODS HTML destination?
a. the SAS data set
b. an ATTRIBUTE statement
c. ODSCOLOR and ODSFONT statements
d. the default ODS style template or template name specified in the STYLE= option



Which data set option selects variables?
a. COL=
b. VAR=
c. KEEP=
d. SELECT=



Which statement selects observations in a procedure step?
a. IF
b. RETAIN
c. WHERE
d. INCLUDE


What sort sequence does PROC SORT use by default?
a. ascending order
b. descending order
c. numeric variable values in descending order and character values in ascending order
d. numeric variable values in ascending order and character values in descending order


Which statements can be used in a PROC PRINT step?
a. TITLE, IF, FORMAT, SET
b. TITLE, LABEL, FORMAT, IF
c. TITLE, LABEL, BY, FORMAT
d. TITLE, LABEL, MERGE, sum


What does a character format name begin with?
a. dollar sign ($)
b. percent sign (%)
c. pound or hash sign (#)
d. character value (a-z or A-Z)


Which FORMAT statement formats the variable Salary with dollar signs, commas, and two decimal places?
a. format Salary $14*2;
b. format Salary $14(2);
c. format Salary dolcom14-2;
d. format Salary dollar14.2;


Which is a valid LIBNAME statement?
a. libname 'c:\sasfiles';
b. libname mylib 'c:\sasfiles';
c. libname 'c:\sasfiles' mylib;
d. libname 'c:\sasfiles' libref=mylib;


Consider the following PROC SORT step:
proc sort data=customers;

run;
Which statement completes the step and sorts the observations in descending order by ID and, within ID, in ascending order by LastName?
a. by ID descending LastName;
b. by descending ID LastName;
c. by descending ID ascending LastName;
d. by ID descending LastName ascending;


Which TITLE statement correctly codes the title Fred's Report?
a. title "Fred's Report";
b. title 'Fred' ''s Report';
c. title ' "Fred's Report" ';
d. title allowquote(Fred's Report);


Which option is used to identify an input SAS data set to a SAS procedure?
a. SET=
b. DATA=
c. INPUT=
d. INFILE=


Consider the following program:

proc print data=customers;
run;
ods html close;
Which statement correctly starts the capture of HTML output and names an HTML result file?
a. ods 'myfile.html';
b. ods file='myfile.html';
c. ods html='myfile.html';
d. ods html file='myfile.html';


Which statement clears all titles?
a. title;
b. title clear;
c. clear_titles;
d. title clear all;


Which statement correctly closes the LISTING destination?
a. ods;
b. ods close;
c. ods listing close;
d. ods _listing_ close;


Where can ODS reports be viewed?
a. a browser
b. a word processor
c. the Output window in the SAS windowing environment
d. all of the above


What happens when a DATA step or PROC step contains multiple WHERE statements?
a. Only the first WHERE statement is processed.
b. The WHERE conditions are combined with a logical AND operator.
c. The last WHERE statement replaces previous WHERE statements.
d. A syntax error is displayed in the log, and the program does not execute.



--------------------------------------------------------------------------------


Leave ur mail id along with comment and i will mail u the ans !.

Thanks,
Kb