BookmarkSubscribeRSS Feed
JaneLi
Calcite | Level 5

hey guys,

I want to read a excel into SAS and just print two column of the table? I don't know how to do with this?

5 REPLIES 5
Reeza
Super User

Just print two columns? So not an output data set, just a list?

Use a List task and select the two variables you would like to display.

JaneLi
Calcite | Level 5

Just to print two columns as a table.

I read my data from library Li, I only want to get two columns: PHYSHLTH,TOLDHI2.   And PHYSHLTH >=5, at the same time TOLDHI2=2).

Can anyone help me with my code??

My code:

libname Li "C:\Users\yl665\downloads";

proc contents data=Li.llcp2011_abridged; run;

Data llcp2011_abridged;

Set llcp2011;

  When (PHYSHLTH >=5 and TOLDHI2=2);

RUN;

Proc print DATA llcp2011_abridged;run

JaneLi
Calcite | Level 5

I read my data from library 1, I only want to get two columns: PHYSHLTH,TOLDHI2. and PHYSHLTH >=5, at the same time TOLDHI2=2).

Can anyone help me with my code??

My code:

libname Li "C:\Users\yl665\downloads";

proc contents data=Li.llcp2011_abridged; run;

Data llcp2011_abridged;

Set llcp2011;

  When (PHYSHLTH >=5 and TOLDHI2=2);

RUN;

Proc print DATA llcp2011_abridged;run

Reeza
Super User

You've posted in EG, I assumed you wanted to use EG Tasks. For coding, its preferable to post in the Procedures Forum.

I have some uncertainties about your code, it seems disconnected though may be correct, see my questions below.

In general you can use VAR statement in proc print to keep variables, assuming you want to display VAR1 and VAR2 something like the following:

Data llcp2011_abridged; /*Is this data set in LI or created somewhere else?*/

Set llcp2011; /*This isn't related to the LI library above?*/

  When (PHYSHLTH >=5 and TOLDHI2=2); /*This should be a WHERE not WHEN*/

RUN;

Proc print DATA llcp2011_abridged; /*This is missing an = sign after the data*/

VAR VAR1 VAR2;

run;

ballardw
Super User

If you have an existing data set and can express the records you want with variables in a single record then there is no need to create an additional dataset. Go directly to proc print with your data set and use a WHERE clause to select the records:

proc print data=Li.llcp2011; /* I put the Li there in case that is the library the dataset resides in you may want to add options NOOBS to suppress the number of observation that will appear with each record and LABEL to print the label instead of the variable name if you have labels assigned.*/

where Physhlth >= 5 and toldhi2=2;

var PHYSHLTH TOLDHI2;

run;

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!

SAS Enterprise Guide vs. SAS Studio

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.

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
  • 1098 views
  • 0 likes
  • 3 in conversation