BookmarkSubscribeRSS Feed
momi
Obsidian | Level 7

I am using the code below as example.  When I add BY statement ( by sex in my example), I get an error saying "

ERROR: Compilation error.

ERROR: Parse encountered BY when expecting end of input.

ERROR: Parse failed on line 122:  >>> by <<<  sex;."

What does this mean? Where can I add the BY statement?

Thank you,

Kayo

proc copy in = sashelp out = work;

    select class;

run;

proc ds2;

data;

    dcl double min;

   by sex;

    retain min;

    keep min;

    method init();

             min = 9999;

    end;

    method run();

             set work.class;

             if weight < min then min = weight;

    end;

    method term();

          output;

    end;

enddata;

run;

quit;

14 REPLIES 14
jakarman
Barite | Level 11

IT means: you cannot use a by statement at that location. Remember DS2 can run multithreaded, it is not the same as old datastep programming.

SAS(R) 9.4 DS2 Language Reference, Third Edition (ds2 language by statement) and SAS(R) 9.4 DS2 Language Reference, Third Edition (example 3)

---->-- ja karman --<-----
CharlotteCain
Quartz | Level 8

Is DS2 language aimed for advance SAS expert programmers like You, friedegg and haikuo et al or new starters lik me who can begin as DS2 language programmers? I read the functionality of intersecting sql and datastep, but from learning point of view, I'd like to know whom it is suited for?

FriedEgg
SAS Employee

, there is no reason to avoid DS2 or view it as something directed towards 'experts.'  While the learning curve may be view-able as steeper (which I would say depends on your background), it is a useful tool for any programmer.  I would recommend the following paper as a nice introduction to the procedure:

http://support.sas.com/resources/papers/proceedings14/1283-2014.pdf

CharlotteCain
Quartz | Level 8

Thank you Sir for your encouraging words. And you are too right!, the learning is indeed steep for the simple reason my grasping power of the vast concepts is much slower than the normal ones and comparing to you(expert) folks, my brain functions perhaps at 1/10th of your speed.  Nevertheless, I am determined not to give up despite how hard it presents.

I am just in awe of the fact to notice how quickly you guys grasp, understand, remember and apply, while SAS being extremely vast.  as it is or is it that you worked so hard losing all your sleep when you began learning this language. Anyways, Many thanks Once again Sir and happy new year.

Cheers,

Charlotte from England!

FriedEgg
SAS Employee

As said, mostly it's just having experience and I'll add: reading, a lot...

momi
Obsidian | Level 7

Thank you!

FriedEgg
SAS Employee

A BY statement must be preceded by statement to which it is meant to apply to.

51   proc ds2;

52   data;

53   dcl double min;

54   method run();

55   min=9999;

56   do until(last.sex);

57   set class;

58   by sex;

59   min = min(weight, min);

60   end;

61   put sex= min=;

62   end;

63   enddata;

64   run;

sex=F min=50.5

sex=M min=83

FriedEgg
SAS Employee

Or, a even better way, for DS2 would be to just use a SET statment with a SQL query

66   proc ds2;

67   data;

68   method run();

69   set {select sex, min(weight) as min from class group by sex};

70   put sex= min=;

71   end;

72   enddata;

73   run;

SEX=F MIN=50.5

SEX=M MIN=83

74   quit;

Haikuo
Onyx | Level 15

Nice. I can see the prime time of DS2 is coming. This vaguely reminds me of the Partitioning function in PL/SQL. 

momi
Obsidian | Level 7

I have another question.  How can I save the output?  I am not sure where I add the code.

Thanks,

Kayo

FriedEgg
SAS Employee

Instead of a null data statement put you desired output name, just like the regular data step.

proc ds2;

data want;

method run();

set {select sex, min(weight) as min from class group by sex};

put sex= min=;

end;

enddata;

run;

quit;

momi
Obsidian | Level 7

Thanks!  It works!

jakarman
Barite | Level 11

Charlotte, all depends on your background, the technical environment and your personal goals.

You are seeing init run sections, those are part of SAS/AF scl language in a similar way.  The DS2 language is different to a dataset: SAS(R) 9.4 DS2 Language Reference, Third Edition (getting started).

When you:

- are mainly connecting to an external DBMS

- trying to use the functionality of that external DBMS as much as possible.

- Understand threading parallel processing and more strict type processing (object oriented)

Than you are a programmer that could well benefit from DS2

When you:

- are still using the way of thinking by using Excel

- Wanting all data being processed as SAS datasets and using SAS procs

- May be using only a click/drag programming interface

Than you are a programmer that could face a lot of problems learning - using DS2  

---->-- ja karman --<-----
jakarman
Barite | Level 11

Charlotte, it are not your brains that are of different speed. It is the way of recognizing similar patterns.

A lot in ICT - Analytics - organization processes - coming back over and over again with different buzz-words or acronyms. A would wish those patterns would be documented more clearly.

Once getting used to that and seeing those patterns makes it all more easy.

---->-- ja karman --<-----

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!

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
  • 14 replies
  • 2126 views
  • 5 likes
  • 5 in conversation