Reading name ranges from Excel to SAS - sas

I have around fifty names ranges in excel from multiple worksheet. I want to assign each of these rangename value to a variable in SAS. These values in excel rangename is dynamic. I want to make sure that when I run the sas code, it assign the value correctly. Can someone help me how to do this?

Related

Variable names incompatible between SPSS and SAS

I imported an SPSS (.sav file) into SAS. Several of the variables are not showing up as they are named things like 'variable___1.1' When i try to KEEP certain variables in a data step, I get an error because these variables create an error as SAS misinterprets the '.'
Has anyone encountered this before or know a way around it?
I can see the problem variables and their values in the .sas7bdat file, so the data imported, I just need to find a way to change the variable name so I can include it in the report.
You use name literal notation, 'variable1_1'n in your code, e.g.
rename 'variable___1.1'n = variable1_1;
Or set this option and reimport your data so that you get better names.
option validvarname=v7;
That will tell SAS to import the data with simpler variable names. Note that I'm not sure if that's two underscores or three or four in the variable name....guessing at 3.

Can Query Builder in SAS EG be used to output fixed-width columns?

thanks for any help! I’ll try to be concise.
I am new to SAS and have inherited a SAS run that outputs a table with 15 columns, which I export as an excel file and deliver.
The recipient would now like it as a .txt file with fixed-width columns, and has provided the character limit/width for each column.
Is this something that can be done in query builder, so I can just query the existing table rather than modifying the code in the run? I tried filling the field for ‘Length’ when you add a column to query builder, but it did not have the desired result.

How to read SAS format dictionary into SPSS?

I am trying to load SAS data file together with its variable and value labels, but I cant seem to make it work.
I have 3 SAS files
sas data ("data_final.sas7bdat")
sas format dictionary that contains the format name, variable name/labels, etc ("formats.sas7bdat")
sas format library that contains the format name, value name/labels,etc ("format_library.sas7bdat")
I am trying to load this to SPSS using the following code but it doesn't work. It loads the data and the variable labels but not the value labels.
GET SAS DATA='\data_final.sas7bdat'
/FORMATS='\formats.sas7bdat'
/FORMATS='\format_library.sas7bdat'.
Any help is greatly appreciated.
Thank you!
The FORMATS= option wants the name of the SAS format catalog, not another SAS dataset. Catalogs use sas7bcat as the extension.
GET SAS DATA='\data_final.sas7bdat'
/FORMATS='\formats.sas7bcat'.
If you really cannot get it to work then read in the formats_library.sas7bdat and look at the FMTNAME, TYPE, START, END and LABEL variables and use those to generate the SPSS code you need to attach data labels to your SPSS data.
FMTNAME is the name of the format. The TYPE determines if it is applies to character values or numeric values (or if in fact is an INFORMAT instead of FORMAT). The START and END mark the range of values (frequently they will be the same) and LABEL is the decoded value (aka the data label). Unlike in SPSS in SAS you only have to define the code/decode mapping once and then apply to as many variables as you want.
The dataset you show as being named formats.sas7bdat looks like it is the variable level metadata. That should list each variable (NAME) and what format, if any, has been attached to it (FORMAT). So if that shows there is a variable named FRED that has the format YESNO attached to it then look for records in format_library where FMTNAME='YESNO' and see what values it maps. So if FRED is numeric with values 1 and 2 then format YESNO might have one record with START='1' and LABEL='YES' and another with START='2' and LABEL='NO'.

Tablename too long in PROC COMPARE

I am trying to compare two tables using SAS code in PROC COMPARE.
The Table names are too long- they pass the 32 character limit.
I cannot re-name the files in the Source Database.
Is there anyway to get around this? I tried assigning to a variable, but that doesn't work.
you can create a view with a valid sas name (ie length name <= 32) and then use the view in proc compare.
Thankyou francesco. I started creating the views, but it was taking a long time as i had to create the source table as views as well. I decided to output the results to a text file and 'Compare' using Notepad ++. Great pluggin! :)) works wonders :)

Probt in sas for column of values

Im looking do a probt for a column of values in sas not just one and to give two tailed p values.
I have the following code Id like to amend
data all_ssr;
x=.551447;
df=25;
p=(1-probt(abs(x),df))*2;
put p=;
run;
however I would like x to be a column of values within another file. I have tried work.ttest which is just a file of ttest values.
Many thanks
You need to use a set statement to access data from another SAS dataset.
data all_ssr;
set work.ttest; /*Dataset containing column of values*/
df=25;
p=(1-probt(abs(x),df))*2;
run;
Removing the put statement avoids clogging up the log.