Hi. How can I print first 50 rows of a worksheet in an excel sheet in SAS Studio? And for the data selected from the worksheet, how to print the Date as mm/dd/yy, and Gross with dollar signs and commas. I'm using the University Edition. Thank you so much.
Import Excel data into a SAS dataset and use obs=50 as a dataset option when using proc print to print the dataset.
Assign proper formats to the variables in question. The documentation of formats is found here.
Here is what I have:
proc print data=work.Movie_2019 (obs=15);
format MMDDYY10. ;
format DOLLARw.d ;
format COMMAw.d;
run;
It gives the error message:
To assign a format to a variable, you need to have both the variable name and the format in the format statement.
See the documentation for this.
Is this correct?
proc print data=work.Movie_2019 (obs=50);
format ReleaseData MMDDYY10.;
run;
Or should there be space or _ between Release and Data
I have only one variable, however, the title of the variable in the excel sheet is "Release Date". I'm struggling with the format. Should it be Release Data, Release_Data or ReleaseData? Or should I do something else? Thank you.
@aabbccwyt wrote:
I have only one variable, however, the title of the variable in the excel sheet is "Release Date". I'm struggling with the format. Should it be Release Data, Release_Data or ReleaseData? Or should I do something else? Thank you.
Then you need to use a so-called "name literal", which allows to use almost any crap as a variable name:
format "Release Date"n mmddyy10.;
I think I have everything right, however, the format is still wrong. Can you please check my code to see if there is anything wrong? Thank you.
proc import datafile="/home/Movies_Database_2018.xlsx"
dbms=xlsx out=Movies_2018 replace;
run;
proc print data=Movies_2018 (obs=50);
format Gross dollar2.;
format Gross comma10.;
format "Release Data"n mmddyy10.;
run;
The data is just fine, just the format is not correct at all. No error, just a warning says " Variable 'Release Data'n not found in data set MOVIES_2018.
View the dataset to see the variable name with which it was imported, or run proc contents on it and look at the results.
Don't guess your names and variable types, check it explicitly. Especially from Excel files because then SAS guesses at types, whereas with a text file you can control the type.
Run a proc contents on your data set that you imported and it will list the variable names and labels.
proc contents data=movies_2018;
run;
If you're still having issues after this, please post the output from PROC CONTENTS to the forum.
@aabbccwyt wrote:
I think I have everything right, however, the format is still wrong. Can you please check my code to see if there is anything wrong? Thank you.
proc import datafile="/home/Movies_Database_2018.xlsx"
dbms=xlsx out=Movies_2018 replace;
run;
proc print data=Movies_2018 (obs=50);
format Gross dollar2.;
format Gross comma10.;
format "Release Data"n mmddyy10.;
run;
The data is just fine, just the format is not correct at all. No error, just a warning says " Variable 'Release Data'n not found in data set MOVIES_2018.
The data is just fine, just the format is not correct at all. No error, just a warning says " Variable 'Release Data'n not found in data set MOVIES_2018.
Why did you reference a variable that doesn't exist? Could be just a typo. I doubt that the name is 'Release Data'n for a value that has a date in it.
Make sure not to use the LABEL of the variable instead of the NAME of the variable. The setting of the VALIDVARNAME option will determine whether SAS will create a variable named 'Release Date'n or Release_Date, but in either case the label will reflect the column header in the Excel file.
Also why are you using two different FORMAT statements for the variable GROSS? Which way would you like it to display the values? With or without DOLLAR signs?
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.