Hello,
The below is my code to import excel file with SAS studio. When I run step by step, the output variables had space, like 'Test A', 'Test B' (fig2 below). However, when I run all steps together, the output variables changed into "Test_A", 'Test_B' (fig. 3 below).
My question is how I set up my SAS studio or revise my code to get fig.3 output when running the code step by step. Thanks
options validvarname=v7; /*Step 1*/ proc import datafile="...\test.xlsx" out = test dbms=xlsx replace; /*step 2*/ getnames=yes; sheet='Sheet1'; run;
Below is test.xlsx
Fig.2
Fig.3
When I used SAS EG or PC SAS, I never met above issue.
Do you mean that you ran the second part without ever running the first part? (Or after restarting your SAS session that SAS/studio is using to run your SAS program code).
Or are you saying that if you run that as two separate submissions in the same SAS/Studio session it works differently than when you submit the whole program at once?
If the former then change the setting VALIDVARNAME to what you want in your AUTOEXEC file.
If the later then check what code SAS/Studio is submitting before/after each submission of code in your editor window. It must be resetting VALIDVARNAME in that code.
To see what type of random code SAS/Studio is inserting you can change a preference setting.
Check the "Show generated code in the SAS log" box.
There is also a setting "SAS variable name policy" that should change the validvarname option.
Thanks.
It is strange and easy make errors, if the outputs are differences by running step by step or as a whole. I checked the preference in SAS studio page, and did not find somewhere I can change to remove this issue.
What should I do to remove this kind of issue? Should I ask our IT department to reset the environment? Please advise. Thanks
To some degree, If you run the exact same code, in the same system you should expect the same results.
From the code shown, you shouldn't see a difference. You didn't show your full code so it's hard to tell where the difference is. If you feel there is a real difference between the two options, run it using one method and then run a proc contents on the file. Then do the same with the other methodology. They should be exactly the same.
I would not expect the same results running on different systems with PROC IMPORT as it's a guessing procedures and by definition it can guess differently. If the file changes monthly you also cannot guarantee that you'll get the same results from month to month, as the data changes there's a small chance that SAS will read in columns with different types and formats.
In general, if you're automating a process it's rare to use PROC IMPORT as it's not consistent, import your data using a data step if you need that type of consistency.
I run the code in the same environment and same session . The only difference is: one is I submitted separately and another is I submitted the code together. I checked the log by adding "proc options option=validvarname; run;" for the first way I got validvarname=any, and for the second way I got validvarname=v7. That is what I felt some strange.
Thanks a lot. I changed as you said. It works.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.