BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
jenfumi
Obsidian | Level 7

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

1 ACCEPTED SOLUTION

Accepted Solutions
SuzanneDorinski
Lapis Lazuli | Level 10

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.

 

Icon at the top of the screen will display the code that creates the current tableIcon at the top of the screen will display the code that creates the current table

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.

 

Code in the red box at the top of the screen is generated by the icon on the data set tabCode in the red box at the top of the screen is generated by the icon on the data set tab

I opened up my CSV file in Notepad in the screen shot below.

 

CSV file with 3 variables from SASHELP.BASEBALL data setCSV file with 3 variables from SASHELP.BASEBALL data set

View solution in original post

5 REPLIES 5
SuzanneDorinski
Lapis Lazuli | Level 10

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.

 

Icon at the top of the screen will display the code that creates the current tableIcon at the top of the screen will display the code that creates the current table

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.

 

Code in the red box at the top of the screen is generated by the icon on the data set tabCode in the red box at the top of the screen is generated by the icon on the data set tab

I opened up my CSV file in Notepad in the screen shot below.

 

CSV file with 3 variables from SASHELP.BASEBALL data setCSV file with 3 variables from SASHELP.BASEBALL data set

andreas_lds
Jade | Level 19

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;
ballardw
Super User

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;
jenfumi
Obsidian | Level 7

@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. 🙂

jenfumi
Obsidian | Level 7

Thanks guys it worked! =o)


I guess I was just referencing the wrong data set....~J

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 2992 views
  • 3 likes
  • 4 in conversation