Hi Everyone,
I am beginner to DS2 programming.
I have below data step program where i am extracting codes from the calculation string and populating the codes into multiple columns.
I need DS2 equivalent of this code. I would really appreciate your help on this.
Data Test;
input CALCULATION_STRING $ 1-100;
datalines;
(A0003*A0001)*D0020
0
C0012
B0003*D0001*(D0010+D0012)
A0003*A0001*A0019*(D0010+D0012)
C0003*C0001*D0058
E0003*A0001*(D0010+D0012)
D0003*D0001*B0019*(E0010+E0012)
;
run;
DATA Test1;
SET Test;
RET = PRXPARSE("/\w+/");
RETAIN RET;
START = 1;
STOP = LENGTH(CALCULATION_STRING);
CALL PRXNEXT(RET,START,STOP,CALCULATION_STRING,POSITION,LENGTH);
ARRAY CODE[7] $ CODE1-CODE7;
DO I = 1 TO 7 WHILE (POSITION GT 0);
CODE[I] = SUBSTR(CALCULATION_STRING,POSITION,LENGTH);
CALL PRXNEXT(RET,START,STOP,CALCULATION_STRING,POSITION,LENGTH);
END;
KEEP CALCULATION_STRING CODE1-CODE7 ;
run;
proc print data=Test1;
run;
Output of the above code given below.
CALCULA TION_ST RING | CODE1 | CODE2 | CODE3 | CODE4 | CODE5 | CODE6 | CODE7 |
B0003*D000 1*(D0010+D 0012) | B0003 | D0001 | D0010 | D0012 |
C0003*C000 1*D0058 | C0003 | C0001 | D0058 |
D0003*D000 1*B0019*(E 0010+E0012 ) | D0003 | D0001 | B0019 | E0010 | E0012 |
What is ds2 programming? Do you proc ds2, if so give an example of what you have and explain what your question is. And please do not SHOUT your code at us.
Hi,
Apologies for the confusion.
Yes, I meant PROC DS2.
As i am very new to PROC DS2, so wanted to check how do i convert the data step code to PROC DS2.
Ok, sorry, never had any good reason to even look at proc ds2. Perhaps start with:
https://documentation.sas.com/api/docsets/ds2pg/9.4/content/ds2pg.pdf?locale=en
Then some other papers on it (from google search):
https://www.sas.com/storefront/aux/en/spprocds2methods/68945_excerpt.pdf
1. Indeed, any compelling reason to look at DS2? I never found any despite my best efforts.
2. To answer your question: Have you seen this paper? https://www.sas.com/content/dam/SAS/support/en/sas-global-forum-proceedings/2018/2249-2018.pdf
Thank you for the information given below.
There are mainly two reasons for me to look into PROC DS2:
As i am new to PROC DS2, exploring all the available options.
Thank you everyone for the information provided. I will go through this and try to write an equivalent PROC DS2 code for the code mentioned above.
Cheers...
1. Threaded programming is generally only interesting if you have threaded I/Os (i.e. multiple I/O subsystems), otherwise you're just replacing sequential reads with random reads.
2. Hadoop has distributed data nodes, so is a good candidate. Good luck.
3. findw is much faster than prx* functions. Unsure which is best supported by DS2 though.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.