BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
How do I create data using datalines statements or cards statements in the Proc DS2 procedure I step
1 ACCEPTED SOLUTION

Accepted Solutions
_Sas_Beginner_
Quartz | Level 8

THANKS FOR YOUR REPLY! I found another way to use it as a reference if you need it

proc ds2;
data s / overwrite=yes;
drop j;
 declare varchar(16) ds2_array[2,5];
 	 declare double ds2_arrayo[5];
 		declare varchar(16) ds2_array1 ds2_array2 ;
 			dcl double ds2_array3 j;
method run();
ds2_array:=(
'parmcard','Alfred','Alice','Barbara ','Carol ','f','f','f','f','f');
ds2_arrayo:=(1.1,2.1,3.1,4.1,5.1);
	do j=1 to dim(ds2_array,2);
      ds2_array1=ds2_array[1,j];
      ds2_array2=ds2_array[2,j];
	ds2_array3=ds2_arrayo[j];
    	output;
	  end; 
end;
enddata;
run;
quit;

View solution in original post

5 REPLIES 5
_Sas_Beginner_
Quartz | Level 8
I mean, how can I create Data in proc DS2 just like using cards statements in data, and I find that proc DS2 can't use datalines or cards statements
Tom
Super User Tom
Super User

Why not use parmcards instead.

options parmcards=mycards;
filename mycards temp;
parmcards4;
Alfred M 14 69 112.5
Alice F 13 56.5 84
Barbara F 13 65.3 98
Carol F 14 62.8 102.5
;;;;

Now later in your DS2 code you can use INFILE MYCARDS.

_Sas_Beginner_
Quartz | Level 8

@Tom wrote:

Why not use parmcards instead.

options parmcards=mycards;
filename mycards temp;
parmcards4;
Alfred M 14 69 112.5
Alice F 13 56.5 84
Barbara F 13 65.3 98
Carol F 14 62.8 102.5
;;;;

Now later in your DS2 code you can use INFILE MYCARDS.


I've tried your method and it says a "parsing failed" issue, but I've found another way that can be used as a reference if you need it
proc ds2;
data r;
method run();
infile mycard;
end;
enddata;
run;
quit;

The right way is next code

proc ds2;
data s / overwrite=yes;
drop j;
 declare varchar(16) ds2_array[2,5];
 	 declare double ds2_arrayo[5];
 		declare varchar(16) ds2_array1 ds2_array2 ;
 			dcl double ds2_array3 j;
method run();
ds2_array:=(
'parmcard','Alfred','Alice','Barbara ','Carol ','f','f','f','f','f');
ds2_arrayo:=(1.1,2.1,3.1,4.1,5.1);
	do j=1 to dim(ds2_array,2);
ds2_array1=ds2_array[1,j]; ds2_array2=ds2_array[2,j]; ds2_array3=ds2_arrayo[j]; output;
end; end; enddata; run; quit;

 

whymath
Lapis Lazuli | Level 10

According to the SAS Blog <Reasons to love PROC DS2>: 

DS2 is not a replacement for the DATA step as INFILE, INPUT, FILE, PUT, and DATALINES statements aren’t permitted.

But you can use variable assignment statement and output statement.

proc ds2;
data one(overwrite=yes); 
  declare int x;
    method run();
      x=1;
      output;
    end; 
  enddata;
run;
quit;
_Sas_Beginner_
Quartz | Level 8

THANKS FOR YOUR REPLY! I found another way to use it as a reference if you need it

proc ds2;
data s / overwrite=yes;
drop j;
 declare varchar(16) ds2_array[2,5];
 	 declare double ds2_arrayo[5];
 		declare varchar(16) ds2_array1 ds2_array2 ;
 			dcl double ds2_array3 j;
method run();
ds2_array:=(
'parmcard','Alfred','Alice','Barbara ','Carol ','f','f','f','f','f');
ds2_arrayo:=(1.1,2.1,3.1,4.1,5.1);
	do j=1 to dim(ds2_array,2);
      ds2_array1=ds2_array[1,j];
      ds2_array2=ds2_array[2,j];
	ds2_array3=ds2_arrayo[j];
    	output;
	  end; 
end;
enddata;
run;
quit;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 5 replies
  • 381 views
  • 2 likes
  • 3 in conversation