BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
LFern
Obsidian | Level 7

Hello,

I have:

data have;
input country $6. min max ;
datalines;
Canada 495 507
Haiti 10 15
;
run;

I want either of these versions (they're substantively the same but one is long-format and the other is wide-format):

Wide format:

want1.PNG

Long format:

want2.PNG

 

Any suggestions?

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

@LFern wrote:

Hello,

I have:

data have;
input country $6. min max ;
datalines;
Canada 495 507
Haiti 10 15
;
run;

I want either of these versions (they're substantively the same but one is long-format and the other is wide-format):

Wide format:

want1.PNG

Long format:

want2.PNG

 

Any suggestions?


data want;
  set have;
  do in_range=min to max;
     output;
  end;
  keep country in_range;
run;

If you want the "wide" version you could use proc transpose but can't see any real advantage to that.

 

I have to assume you wanted the integer versions. "All values", in a mathematical sense, is an infinite number of values regardless of the range.

View solution in original post

3 REPLIES 3
ballardw
Super User

@LFern wrote:

Hello,

I have:

data have;
input country $6. min max ;
datalines;
Canada 495 507
Haiti 10 15
;
run;

I want either of these versions (they're substantively the same but one is long-format and the other is wide-format):

Wide format:

want1.PNG

Long format:

want2.PNG

 

Any suggestions?


data want;
  set have;
  do in_range=min to max;
     output;
  end;
  keep country in_range;
run;

If you want the "wide" version you could use proc transpose but can't see any real advantage to that.

 

I have to assume you wanted the integer versions. "All values", in a mathematical sense, is an infinite number of values regardless of the range.

LFern
Obsidian | Level 7

oh gosh this is so simple and clean! I was working through loops and arrays for no reason. Thank you so much!

ballardw
Super User

@LFern wrote:

oh gosh this is so simple and clean! I was working through loops and arrays for no reason. Thank you so much!


If you were doing that to attempt a wide solution then you see why wide is very frequently not a good idea.

 

 

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!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 575 views
  • 1 like
  • 2 in conversation