vikas rana


{ City } delhi
< Country > india
* Profession * senior data analyst
User No # 111109
Total Questions Posted # 0
Total Answers Posted # 3

Total Answers Posted for My Questions # 0
Total Views for My Questions # 0

Users Marked my Answers as Correct # 3
Users Marked my Answers as Wrong # 0
Questions / { vikas rana }
Questions Answers Category Views Company eMail




Answers / { vikas rana }

Question { IBM, 4547 }

6) Explain about below automatic variables
a) _N_
b) _ERROR_
c) _CHAR_
d) _NUMERIC_
e) _ALL_
f) FIRST.BY VARIABLE
g) LAST.BY VARIABLE
h) _NAME_
i) _TYPE_
j) _FREQ_
k) _STAT_
l) _BREAK


Answer

Automatic variables are created automatically in the data statements and they are added to the PDV but not ouput to
to the resulting dataset which we want.

1)_N_ : number of times the data step has iterated. initially it is 1 and it's counter increases +1 , every time data steps crosses the data statements.

2)_ERROR_: It is 0 by default but is set to 1 every time
the error is encountered.

3)_CHARACTER_ : could be defined in the arrays and other data step programming to include all the character variables.

4)_NUMERIC_ : To include all the numeric variables

5)First.by variable and LAST.By : Whenever, we define a BY parameter with the SET statement, by default two
automatic variables are created in the background and we can utilize them for limiting the rows which we are interested in . {http://support.sas.com/documentation/cdl/en/lrcon/62955/HTML/default/viewer.htm#a000761931.htm}

7) _NAME_ : During transpose the variables you define in VAR statment are transposed and they comes in _NAME_ variable.

proc transpose data=x out=y prefix=m;
by variable1;
id variable2;
var variable3;
run;

8)_TYPE_ and _FREQ_: When you use PROC SUMMARY or PROC MEANS and we define Class parameter for two variables, and we use CHARTYPE in our Proc summary options, then
we get two automatic variables _TYPE_ and _FREQ_ . We can utilize it to limit the output we need.

9)_STAT_ :The default output of PROC MEANS, when no statistics are listed in the OUTPUT statement, is a data set containing a _STAT_ variable and the variables listed in the VAR statement. The output data set contains five records, one for each default statistic N, MIN, MAX, MEAN, and STD.

10) _BREAK_ : PROC report automatically create a variable
_BREAK_.

Is This Answer Correct ?    3 Yes 0 No

Question { Tech Mahindra, 3521 }

i have multiple .csv files in a unix directory.
every file is having variable names as header.even for empty file also.

suppose take 3 files
a.csv
b.csv
c.csv

a.csv contains data as
name;age,salary;
raja;34;4000;
ravi;33;5000;
kumar;25;3000;

b.csv contains data as
name;age,salary;
ajay;40;4500;


and c.csv contains
name;age,salary; (only headers)

Now i want to import and append all these files in to a single dataset.

i tried infile statement with *.csv to import all at a time.

but i m not getting correct data.
please help me . its urgent.
thank you in advance


Answer

/*So for this, you have to create a macro to store the path of the folder where your files are located .*/

/*STEP 1:*/

%let dirname = C:UsersRANAJIDesktopSAS_Class_CodeMultiple_csv_files;
filename DIRLIST pipe "dir /B &dirname*.csv";

data dirlist ;
length fname $256;
infile dirlist length=reclen;
input fname $varying256. reclen ;
run;
proc print data = dirlist;
run;

/* so , once your all files are located there, you can proceed with step 2 */

/* Step2*/

data all_text (drop=fname);
length myfilename $100;
length name $25;
set dirlist;
filepath = "&dirname"||fname;
infile dummy filevar = filepath length=reclen end=done missover;
do while(not done);
myfilename = filepath;
input name $ x1 x2 x3;
output;
end;
run;
proc print data=all_text;
run;

you will have all the files appended in the new dataset.

Is This Answer Correct ?    0 Yes 0 No


Question { Tech Mahindra, 3521 }

i have multiple .csv files in a unix directory.
every file is having variable names as header.even for empty file also.

suppose take 3 files
a.csv
b.csv
c.csv

a.csv contains data as
name;age,salary;
raja;34;4000;
ravi;33;5000;
kumar;25;3000;

b.csv contains data as
name;age,salary;
ajay;40;4500;


and c.csv contains
name;age,salary; (only headers)

Now i want to import and append all these files in to a single dataset.

i tried infile statement with *.csv to import all at a time.

but i m not getting correct data.
please help me . its urgent.
thank you in advance


Answer

/*step 1: create a macro for the destination folder */

%let dirname = C:UsersRANAJIDesktopSAS_Class_CodeMultiple_csv_files;
filename DIRLIST pipe "dir /B &dirname*.csv";

data dirlist ;
length fname $256;
infile dirlist length=reclen;
input fname $varying256. reclen ;
run;
proc print data = dirlist;
run;

/* step 2 , append all the files in one. */
data all_text (drop=fname);
length myfilename $100;
length name $25;
set dirlist;
filepath = "&dirname"||fname;
infile dummy filevar = filepath length=reclen end=done missover;
do while(not done);
myfilename = filepath;
input name $ x1 x2 x3;
output;
end;
run;
proc print data=all_text;
run;

Is This Answer Correct ?    0 Yes 0 No