BookmarkSubscribeRSS Feed
KidCat
Fluorite | Level 6

Hi,

 

I wrote some DS2 package code, working fine except for one tiny thing.

The "method execute" part creates a datagrid variable MYRESULT.

Depending on some if-then-elses, I would like to populate this datagrid variable.

 

dcl double Row_Num ;

datagrid_addcharactercolumn(MYRESULT, '1st_Col');

datagrid_addcharactercolumn(MYRESULT, '2nd_Col');

datagrid_addcharactercolumn(MYRESULT, '3rd_Col');

datagrid_addnumericcolumn(MYRESULT, 'Row_Num');

 

(...)

if doh-doh-doh then do;

   Row_num=datagrid_addrow("MYRESULT");

   datagrid_set('MYRESULT', '1st_Col', Row_Num, 'MyEntry1'));

   datagrid_set('MYRESULT', '2nd_Col', Row_Num, 'MyEntry2');

   datagrid_set('MYRESULT', '3rd_Col', Row_Num, 'MyEntry3');

end;

(...)

;

if dah-dah-dah then do;

   Row_num=datagrid_addrow("MYRESULT");

   datagrid_set('MYRESULT', '1st_Col', Row_Num, 'MyEntry1'));

   datagrid_set('MYRESULT', '2nd_Col', Row_Num, 'MyEntry2');

   datagrid_set('MYRESULT', '3rd_Col', Row_Num, 'MyEntry3');

end;

 

DS2 creates MYRESULT and four columns.

Assuming these two conditions apply,  I'd expect Row_Num to be populated with 1 and 2.

However, it's empty. Any idea why?

Any pointer appreciated!

4 REPLIES 4
alexal
SAS Employee

Return data type for DATAGRID_ADDROW function is integer. You have declared Row_Num variable as a double. Please change data type and try again.

KidCat
Fluorite | Level 6

Adjusting to integer didn't solve the issue.

alexal
SAS Employee

Try to print it before inserting to the data grid. Do you see anything there?

KidCat
Fluorite | Level 6

In this case, the grid variable is the only result.

My original question tends to change to how to properly implement a _N_ equivalent using DS2...

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 570 views
  • 0 likes
  • 2 in conversation