BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
80sMetalForever
Calcite | Level 5

From my searches seems the answer is NO but wanted to confirm...can I write the following on one line?

DATA ...

IF field1='testing' THEN

DO;

     field2='testing';

     field3='testing';

END;

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

You can write a whole SAS program on one line, as long as the STATEMENTS are ended by semicolons. I don't know if EG imposes a stricter format. - PG

PG

View solution in original post

6 REPLIES 6
PGStats
Opal | Level 21

You can write a whole SAS program on one line, as long as the STATEMENTS are ended by semicolons. I don't know if EG imposes a stricter format. - PG

PG
TomKari
Onyx | Level 15

EG actually submits the code to SAS, so any rules that apply to SAS also apply to EG.

However, EG does have a nice code formatting utility...I find it great when I've hacked out some code, and can pretty it up before posting (I don't know if Display Manager has the same; I'm far from expert with it.)

Therefore, no problem submitting anything as one line...just don't make me maintain it!!

Tom

ChrisHemedinger
Community Manager

More about the EG code formatter:

Hope for ugly programs - The SAS Dummy

Chris

Learn from the Experts! Check out the huge catalog of free sessions in the Ask the Expert webinar series.
Anotherdream
Quartz | Level 8

It is important to point out that Macros actually have a distinct line length that cannot be passed.

For example, if you wrapped your code into a macro and then put it all on one line (and it was a long code) it would actually fail because sas wouldstop compiling it after the Xth position (It depends on versions I believe).

So yeah, don't put your entire code on one line if you are wrapping it in a macro.

Source of Knowledge: I made this mistake once before.

ballardw
Super User

Since SAS uses the semicolon as a statment ender it doesn't really care too much.An entire program could be on one line with only the white space between variables and functions to allow proper parsing by the complier.

However since people will be involved with maintaing the code it is a good idea to adopt some set of practices that use readibility as a criterion.

For example compare quick understanding of the code

if i = var1 then do; var1=3; m= catx(' ', var2,var3, v10); end; else do; var1=var3; end;

with

if i = var1 then

     do;

          var1=3;

          m= catx(' ', var2,var3, v10);

     end;

else

     do;

     var1=var3;

end;

And the complier wouldn't care if you had:

if i =

     var1

               then do; var1=3; m=

catx(' ', var2,var3, v10); end;

else

               do;

     var1=

                         var3;

          end;

sas_9
Obsidian | Level 7

@80,

i think your code will do nothing except creating 3 variable field1, field2 and field3...if you simply want to create 3 field with same value,

data want;

field1='string';

field2='string';

field3='string';

run;

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 2558 views
  • 0 likes
  • 7 in conversation