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

SAS For Dummies 3rd Edition! Check out the new edition, covering SAS 9.4, SAS Viya, and all of the modern ways to use SAS!
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;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

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