SAS studio - formatting - sas

I am attempting to format variables in SAS studio which have been truncated due to the name being longer than 32 characters, when I attempt to format the variables in SAS studio it gives the warning 'this variable in uninitialized'. when I run the same code in SAS EG against the same excel document imported, the code works fine and formats the variable. Why would the same code in SAS studio not work?
code:
data test;
set test1;
format 'variable'n best12.;
run;

Compare the value of option VALIDVARNAME in EG vs Studio. Set it in studio to the same as EG.

Two common ways to view the current setting of an option. Proc OPTIONS or function GetOption
proc options option=validvarname;
run;
%put %sysfunc(getoption(validvarname));

The code won’t be the same because you’re using two different applications with different default settings most likely. As someone else indicated, it’s likely the validvarname option that’s the issue. I would recommend setting it to V7 which avoids these issues. With this setting, SAS converts them to valid variable names by default and you can avoid the rename step entirely.
Supposedly the 32 char limit will be lifted in SAS 9.5. No release date has been announced, SAS 9.4 M5 was recently released so I’m not expecting it super soon.

Related

Read a sas7bdat file in SAS Studio

I've scoured the internet but cannot seem to figure this out. My question is, if I have a sas7bdat file, how can I read a sas7bdat file in SAS studio so that I can work with it.
I've tried:
libname test 'C:\Users\name\Downloads\test.sas7bdat';
which gives me the error that library test does not exist and if I try the following, I know that I need an INPUT which I don't know of unless I can see into the file.
DATA test;
INFILE 'C:\Users\lees162\Downloads\test.sas7bdat';
RUN;
Is there something I'm missing?
Libref's that you create via the LIBNAME statement point to directories, not individual files.
libname test 'C:\Users\name\Downloads\';
INFILE is for reading raw data files. To reference an existing SAS dataset you use a SET statement (or MERGE,MODIFY,UPDATE statement).
set test.test ;
Note that you can skip defining a libref and just use the quoted physical name in the SET statement.
DATA test;
set 'C:\Users\lees162\Downloads\test.sas7bdat';
RUN;
Of course to use C:\ in the paths this is assuming that you are using SAS/Studio to point to full SAS running on your PC. If you are using SAS University Edition then it is running in a virtual machine and you will need to put the SAS dataset into a folder that is mapped to the virtual machine and then reference it in the SAS code with the name that the virtual machine uses for the directory.
So something like:
DATA test;
set '/folders/myfolders/test.sas7bdat';
RUN;
Libname is just pointing the location and once you have done that you can use that libname followed period and dataset in your set statement
libname test "C:\Users\name\Downloads";
DATA test;
set test.asl;
RUN;
One possible reason could be that you are using the SAS University edition (It doesn't support variable library address).
From one of the SAS community Q/A:
"When you are using the SAS University Edition, any libraries that you create must be assigned to a shared folder. You access your shared folder with this pathname: /folders/myfolders/. Always use '/' in the directory path, even in Windows operating environments"
After setting the directory address, proceed as instructed by Tom above in one of the answers.
Suppose you have the sas dataset at location. C:\Users\name\Downloads\test.sas7bdat
libname download 'C:\Users\name\Downloads';
proc sql;
select * from downloads.test;
run;
you can read your dataset like a table using the proc sql, in case you want to query the dataset, but if you want to modify the existing dataset then you can use the data setp as mentioned by #krian.

How to find SAS version from SAS Enterprise Guide?

In my previous work place where I had access to base SAS (running SAS interactively on the server directly), I could find out the current SAS version easily (from the SAS log) by issuing the code proc setinit; run;
In my new work place there is no base SAS - only Enterprise Guide. I try running the same code but the SAS version does not appear in the SAS log.
I would like to easily find out the SAS version running on the server from Enterprise Guide. Is this possible or not? If so, how?
The values you're looking for are stored in automatic macro variables in your system. The code below retrieves the macro variables and prints them to the log for your information.
%put ** my information;
%put short version: &sysver;
%put version: &sysvlong4;
%put site #: &syssite;
%put cpu: &sysscp &sysscpl;
EDIT: Update answer
You can use PROC PRODUCT_STATUS which is great, since it will print the relevant information to the log.
proc product_status;run;
There are some other options available rather than using the global macro variables (&sysver and &sysvlong4), if you prefer point-click options.
First, under Help -> About SAS Enterprise Guide, if you select 'Configuration Details' you can see your SAS system version.
Second, if you select the server in the Servers tree (in the window on the bottom left), and right click->Properties, you will see the SAS version/etc. information.
Third, if you continue in that and select "View Initialization Log", it will show you the initialization log (the bit SAS shows when you start a session in the log). This includes the version number and some other useful information.
Just run the following code and all available information will be printed automatically.
proc setinit;
run;
You can also use
%put _all_;
that will display all macro variables available in your session.
proc setinit;
run;
You can run this set of code and check the results. It will tell you the version you are using.
%put &_clientversion; gives you version.
proc setinit;
run;
Or under the help tab in the top left of the enterprise guide.

Error W/ PROC GEOCODE

Hopefully someone out there will have run into this before. I'm trying to use the street level geocoding capability of SAS' PROC GEOCODE, but I keep getting a cryptic error. I couldn't find anything on the net about it (although to be fair I only spent a half hour looking).
First, I'm using SAS Enterprise Guide (I've tried on both v4.2 and v4.3), although I still prefer to program as I find the point and click interface quite limiting. Maybe this right here is my problem?
Anyway I first get the lookup data sets from http://support.sas.com/rnd/datavisualization/mapsonline/html/geocode.html and follow the instructions in the readme. I also use the pre-written SAS program to import the CSV files. My input dataset contains just 4 variables: street address, city, state, and zip. I then run the following code:
libname josh 'C:\Users\Josh\Desktop\Geocode\SAS files';
proc geocode
method=street
data=SASUSER.Home_Policy_Address_Detail
lookupstreet=josh.USM
out=test;
run;
However I get this error:
ERROR: Variable NAMENC not found in JOSH.USM data set.
Nowhere in the readme or the import program is a variable named "NAMENC" ever mentioned. This is what has me stumped. Is it something wrong with the simple PROC GEOCODE program I wrote? Is it due to me using SAS EG (although I've yet to run into a base SAS procedure that hasn't worked on EG)? Or something else?
Any help/guidance would be much appreciated. Thanks in advance!
Check your SAS version. You can use the 'Help' menu in DMS mode or submit this statement:
%put &sysvlong;
It looks like you are using SAS 9.3 but your lookup data JOSH.USM is the lookup data formatted for SAS 9.4.
PROC GEOCODE street lookup data comes in two slightly different formats, one for SAS 9.3 and another for 9.4. When you download the nationwide lookup data from the SAS MapsOnline geocoding page, make sure to download the version appropriate for your SAS release.

Export SAS data to SPSS, date and datetime

I have data inside SAS.
I want to store the datafile to SPSS format (*.sav)
I use the following program:
PROC export Data=SASdataToStoreInSPSS
FILE="Path\Filename_%sysfunc(today(),date9.).sav"
dbms=sav replace;
RUN;
This works great. Except when I open the file in SPSS the dates are strangly formatted.
For example:
156405 08:51:00
Should be
3-Jan-2011 08:51
I can manually change the data formats in SPSS. So the values are correct date values, except they are not automatically formatted in a readable format.
I tried to change the format in SAS before saving to DATETIME20. or DATETIME23.3. But this does not help.
I want this to work without having to open SPSS and run a Syntax there.
The SPSS files that SAS spits out have to be directly mailed to other users of the data.
I think this is either a bug with SAS's export, or an issue with SPSS where some default changed. What's happening is that SAS is storing it as a SPSS Date - but with width 16, which is not long enough to hold the complete datetime. I don't think you can use DBDSOPTS with DBMS=SPSS, so I don't know that there is a good workaround short of importing the file into SPSS.
You could do that automatically, though, using the SPSS Production facility; I've written an import script before and asked SAS to run spssprod with the batch file. That's an irritating workaround, but it might be the easiest, unless SAS Tech Support can help you (and certainly try that - they are usually only a few hours' turnaround for initial contact at least).
SAS mentioned it has to do with the SPSS driver they use. Apparently it is not an easy fix so they forwarded the issue to second-line tech support.
The workaround you will need is split the dates in two columns. One with date and one with time.
data SPSS2;
set SPSS;
date = put(datepart(DatumSPSS), date9.);
time = put(timepart(DatumSPSS), time8.);
run;
Or you can tell the end user how to change the format of the date in SPSS.
For an automated approach, try this .NET app. You need SPSS, but SAS is not required to convert a large collection of SAS files automatically.
Manual Process included code samples or Application Download

Getting file size of a random file in SAS (Windows)

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.