Hi
I am using SAS University Edition on my MAC and have a huge data set (>2200 variables) saved in a sas7bdat format a colleague provided to me.
How do I export just selected variables (<100) and have it exported to csv format?
I've tried opening the file from my shared folders in SAS studio, clicking on just the variables from the columns section (in the work area) then writing the following export code:
proc export data='LibraryReference.FileName'
outfile='/folders/myfolders/Folder where I want it exported/new csv file name'
dbms=csv
replace;
run;
But the entire data sets gets exported. Any suggestions?
Thanks - J
You're close!
When you look at the data set and select the variables that you want, you can click on an icon near the top of the screen to display the code that creates the current table. The red arrow in the screen shot below is pointing to the icon.
When you click on that icon, a new program tab will open. In the screen shot below, the PROC SQL creates the WORK.query data set. That's what I'll export to CSV.
I opened up my CSV file in Notepad in the screen shot below.
You're close!
When you look at the data set and select the variables that you want, you can click on an icon near the top of the screen to display the code that creates the current table. The red arrow in the screen shot below is pointing to the icon.
When you click on that icon, a new program tab will open. In the screen shot below, the PROC SQL creates the WORK.query data set. That's what I'll export to CSV.
I opened up my CSV file in Notepad in the screen shot below.
You just need the need to add keep= Var1 Var2 ...
proc export data='LibraryReference.FileName(keep=Vars-to-export-separated-by-blank'
outfile='/folders/myfolders/Folder where I want it exported/new csv file name'
dbms=csv
replace;
run;
Example:
proc export data=sashelp.class(keep=Name Age)
dbms=csv
outfile="INSERT_PATH\class.csv"
replace
;
run;
To add to @andreas_lds if your variables have "nice" names that have a common base and suffix such as x1, x2, … xn you can use a list to indicate the variables such as x1 - x50 would get all of the variables x1 through x50. If you want all variables that start with common element then use x: (no space before the colon) . If the variables are adjacent in the data set you can use the two dash list delimiter thisvar -- thatvar. If thisvar is the 5th variable and thatvar is the 23rd variable in the data set then the list represents columns 5 through 23 with out having to list out all of the variables. You can specify multiple lists in a single KEEP statement or dataset option:
proc export data=somefakedata (keep=Name abc1-abc25 freq: this--thatvar) dbms=csv outfile="INSERT_PATH\class.csv" replace ; run;
@ballardw thanks for the tips. I will keep that in mind for the future. Unfortunately for my current situation, the selected variables had multiple prefixes with no more than 3 in common. 🙂
Thanks guys it worked! =o)
I guess I was just referencing the wrong data set....~J
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.