I'm new to SAS and am trying to understand how a specific SAS program is reading data from files:
At this point I understand that libnames tell SAS where to store and retrieve data, but I've also come across this notation at the top of the file I am studying:
%read_configuration_file(dataIn = /*rpe_para.*/configuration_file);
read_configuration_file is a macro my program runs. What I'm really confused about is the dataIn file location. Can somebody explain the notation to me?
/* anything */ is a comment in SAS. The DATAIN parameter has the LIBNAME part commented-out.
Related
I'm trying to convert SAS code to STATA and am encountering some difficulty. Is there an add-in that could do this for me? While I'm new to STATA I don't even have SAS and am unfamiliar with its rules.
Here is the first snippet of SAS code that is a problem:
Libname library 'C:\COFUL\LIB\'; Proc format lib=library;
Value $RCOMT
"D43"="NONE" /*NONE*/
"Z20"="LIT" /*LIT
;
Doing language translation from SAS to something else is hard: there is no getting around that. I have done SAS to C# and it is challenging. You need to know both, as Nick stated. You won't easily find a copy of SAS to use. Check with SAS for a University or Learning edition. That will be limited in the number of obs (recs). SAS is comprised of 2 main things: data steps and procs. These are known as step boundaries. The data step is a very powerful DO/WHILE loop. Procs are a separate beast.
Why would you want to convert to Stata? You would have better luck converting to Python. Read Randy Betancourt's book on Python for SAS users. That would be a start. If you have to use Stata, I am not aware of anyone doing that.
I have to perform statistical analysis on a file with hundreds of observations and 7 variables(columns)on SAS. I know that it is necessary to insert all the observations after "cards" or "datalines". But I can't write them all obviously. How can I do? Moreover, the given data file already is .sas7bdat.
Then, since (in my case) the multiple correspondence analysis requires only six of the seven variables, does this affect what I have to write in INPUT or/and in CARDS?
You only use CARDS when you're trying to manually write a data set. If you already have a SAS data set (sas7bdat) you can usually use that directly (there are some exceptions but likely don't apply here).
First create a libname to the folder where the file is:
libname myFiles 'path to fodler with sas file';
Then load it into your work library - this is a temporary space that is cleaned up when you're done so no files here are saved permanently.
This copies it over to that library - which is often faster.
data myFileName;
set myFiles.myFileName;
run;
You can just work with the file from that library by referencing it as myFiles.myFileName in your code.
proc means data=myFiles.myFileName;
run;
This should get you started, but you should take the SAS free e-course to understand the basics, it will save you time overall.
Just tell SAS to use the dataset. INPUT statement (and CARDS/DATALINES or INFILE statement) are for reading from text files.
proc corresp data='/my directory/mydataset.sas7bdat' .... ;
...
run;
You could also make a libref that points to the directory and use two level name to reference the dataset.
libname myfiles '/my directory/';
proc corresp data=myfiles.mydataset .... ;
...
run;
I am trying to read numeric data from the file. But I am to read it properly the output that I am getting from my SAS program is attached. I recently started learning SAS programming.
I am using SAS University Edition on the windows machine. I already tried by reading data in character as well as numeric formate.
data ds;
infile '/folders/myshortcuts/my_folder/exrate.sas7bdat';
input s ;
run;
I am expecting the same table to be as an output result.
Data File
Output
There are 3 things you need to do:
Make sure that the folder you put the dataset in is accessible to the SAS University Edition VM. Did you follow the setup guide in full? Usually that directs you to set up a folder that becomes available within the VM as /folders/myfolders
Assign a library pointing to the folder using a libname statement.
Use a set statement to access the dataset, not an infile statement. The latter is for reading raw data like csv files.
The sas code should look like this:
libname mylib "/folders/myfolders"; /*Change this to point to your folder path if you're sure you've got the right one*/
data ds;
set mylib.exrate(keep = s);
run;
I have empty rows in SAS after I imported an .xls file.
I'm using the following code but it is not working.
I'm trying to delete all the empty rows.
DATA PROJECT.CLEAN_DATA1;
set PROJECT.merged_data;
if missing(coalesceC(of _character_)) and missing(coalesce(of_numeric_)) then delete;
run;
Please help!
Note: It was “character” in the original post with out “_”.
_CHARACTER_ is the constant that includes all characters in SAS. Try that instead in the condition statement.
And it is a good programming practice to write global constants in SAS as is. So, the condition is -
missing(coalesceC(of _CHARACTER_)) and missing(coalesce(of _NUMERIC_))
I know that the finfo function in SAS returns filesize as one of the info fields in Unix. Is there an equivalent in Windows?
I need to be able to get the total disk space used in a particular folder from within SAS/AF code. Any suggestions would be welcome.
Thanks,
-- A
i've previously posted a sas macro to read windows directory listing here.
If you have SAS version 9.2 or later then this link will work regardless of OS:
http://support.sas.com/kb/38/267.html
Here is a paraphrased version of the link answering your question exactly:
%let filename = d:\sasdev\autoexec.sas;
data info;
length filesize $60;
drop rc fid close;
rc=filename("myfile","&filename");
fid=fopen("myfile");
filesize=finfo(fid,"File Size (bytes)");
close=fclose(fid);
put filesize=;
run;
Cheers
Rob
PS - Have you checked out www.runsubmit.com? It's just like StackOverflow but for SAS related questions only.
I'm going to do something crufty and write a utility function that does the following:
If the file is a SAS dataset, then use standard SAS functions to get the filesize (some lrecl and nobs math)
Otherwise, if it is UNIX or SAS 9.2, use finfo
Otherwise, use a modified version of the macro written by #rkoopmann
Note that this is ok for me only because my requirements are to be able to get the size of a particular file.