BookmarkSubscribeRSS Feed
Hello_there
Lapis Lazuli | Level 10

Hi i'm trying to move the values in GROUP and PARAM in the same column as the values in criteria and put blank rows in between them. What is the most efficient way to do this?

 

data have;
infile datalines dsd dlm=",";
	input group $ param $ criteria $ value $;
datalines;
colors, red, >3, 2
colors, blue, <3, 3
cars, ford, >55, 34
cars, chevy, >23, 45
;
run;

desired output:

Hello_there_0-1669757942150.png

 

edited (how it's supposed to really look like):

Hello_there_0-1669765075791.png

 

 

5 REPLIES 5
PaigeMiller
Diamond | Level 26

Why do you want to change your data set to this really unusual and difficult-to-work-with arrangement?

 

Is it for some sort of table?


Can you provide more of the actual problem, rather than then details of SAS coding?

--
Paige Miller
Hello_there
Lapis Lazuli | Level 10
Hi PaigeMiller, I am working on a table. I agree this is really unusual and it is a difficult-to-work-with arrangement, but that was what requested and that's what i have to work with unfortunately.

The actual problem is the values (group and param) are in different columns but on the same row as the criteria and value (in the original data set). But it's supposed to look like so the group is on top of the param, and both of those are in the same column on top of the criteria text and the word "count". This is difficult for me bc in my real life example there are many combos of group and param and it doesn't do well for me to hard code. I was hoping some others had encountered a similar problem and could share their wisdom on how to navigate this.

I changed the table for what it's supposed to be closer like in the OP.
Tom
Super User Tom
Super User

If you are just trying to print a report just use a data step and the PUT statement.

data _null_;
  set have;
  put group / param / criteria / 'count' @20 value / ;
run;
colors
red
>3
count              2

colors
blue
<3
count              3

cars
ford
>55
count              34

cars
chevy
>23
count              45
Hello_there
Lapis Lazuli | Level 10
Hi Tom,

I'm actually trying to create a data set. But thanks for showing me this.

Hello_there
Lapis Lazuli | Level 10

The best thing i could come up (sort order matters in the end as it will be sorted BY GROUP PARAM CRITERIA). I say this because currently this doesn't match the desired output in the OP, but that's ok.

 

data want; set have; output; output; output; run;
proc sort; by group param criteria; run;

data want1; set want;
   by group param criteria;
    if first.param and first.criteria then count=0; count +1;
    
    if count=1 then do;
    	criteria=group;
    	value="";
    end;
    if count=2 then do;
    	criteria=param;
    	value="";
   	end;
   	
   	keep criteria value;
run;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 1108 views
  • 1 like
  • 3 in conversation