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 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 878 views
  • 2 likes
  • 3 in conversation