BookmarkSubscribeRSS Feed
akhilesh_joshi
Fluorite | Level 6

Hi,

 

I am new to SAS programming. I am finding way to solve the following problem. 

The existing programming prints 2 to 15 levels output. If I would like to print only the levels between a particular value (say 😎 and 15, how do I achieve it using do or do-while loops.

Current sample output:

 

x_2 = x_1+(((1)/15)*y;
x_3 =x_1+(((2)/15)*y);
.
.

.
x_15 = x_1+(((14)/15)*y);

4 REPLIES 4
Astounding
PROC Star

Here's one way:

 

proc format;

value blanks  low-<5, 8 <- high = ' ';

run;

 

proc print data=have;

var x_2 - x_15;

format x_2 - x_15 blanks.;

run;

akhilesh_joshi
Fluorite | Level 6

Hi Astounding,

 

Thanks for your reply. So does that mean that if I specify level 8, it would print only X_9 to X_15? Also, can't it be done using loops? say a do or do-while loop. I am trying to understand the solution you gave. 

 

Thanks, 

Akhilesh

Astounding
PROC Star

This solution prints all the variables, using PROC PRINT.  For any value that is out of range, it prints a blank instead of the actual value.

 

If you don't want to see even those blanks, it takes more complex programming and results in uglier output.  But it can easily be done if that is a better outcome.

ballardw
Super User

Which is why we suggest providing example input and output.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

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.

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
  • 4 replies
  • 609 views
  • 0 likes
  • 3 in conversation