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

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

It's time to register for SAS Innovate! Join your SAS user peers in Las Vegas on April 16-19 2024.
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-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
  • 6 replies
  • 1968 views
  • 0 likes
  • 7 in conversation