DATA Step, Macro, Functions and more

Using arrays?

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 87
Accepted Solution

Using arrays?

Hi all,

I'm attaching an example extract file. Basically all I have is procedure codes which have a certain section or not as shown by section number variables. If a section is present for that procedure code, there is a number similar to section number variable below the variable, otherwise its blank. For instance, for the first procedure code, A9279, I have section 18, 19, 20, 21 and 29 and other sections are blank. Similarly, for procedure code G0108, sections present are 3,31 and 103 and so on.  What i'm looking is following output-

 

procedure_code          section_numbers

A9279                          18,19,20,21,29

G0108                           3,31,103

G0109                           3,31,103

G0151                           19, 40

 

Thanks for your help!

 


Accepted Solutions
Solution
‎09-28-2016 06:49 PM
Super User
Posts: 17,840

Re: Using arrays?

want = catx(",", of section_3--section_103);

View solution in original post


All Replies
Super User
Posts: 10,500

Re: Using arrays?

Many users here don't want to download Excel files because of virus potential, others have such things blocked by security software. Also if you give us Excel we have to create a SAS data set and due to the non-existent constraints on Excel data cells the result we end up with may not have variables of the same type (numeric or character) and even values.

 

This link: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... has instructions on how turn a SAS data set into data step code that can be pasted into the forum or attach as a plain TXT file to allow us to test code and such.

Frequent Contributor
Posts: 87

Re: Using arrays?

Ok, here is the data you can read in sas. I already mentioned the desired output as above. Thanks so much!

 

data WORK.have;
infile datalines dsd truncover;

input Procedure_Code:$5. section_3:$1. section_5:$1. section_7:$1. section_12:$2. section_13:$1. section_15:$1. section_17:$2. section_18:$2. section_19:$2. section_20:$2. section_21:$2. section_22:$2. section_23:$1. section_25:$1. section_26:$2. section_2
8:$2. section_29:$2. section_30:$2. section_31:$2. section_32:$2. section_40:$2. section_65:$2. section_68:$1. section_85:$1. section_96:$2. section_97:$1. section_102:$1. section_103:$3.;
datalines4;
A9279,,,,,,,,18,19,20,21,,,,,,29,,,,,,,,,,,
G0108,3,,,,,,,,,,,,,,,,,,31,,,,,,,,,103
G0109,3,,,,,,,,,,,,,,,,,,31,,,,,,,,,103
G0151,,,,,,,,,19,,,,,,,,,,,,40,,,,,,,
G0152,,,,,,,,,19,,,,,,,,,,,,40,,,,,,,
;;;;

Solution
‎09-28-2016 06:49 PM
Super User
Posts: 17,840

Re: Using arrays?

want = catx(",", of section_3--section_103);
Frequent Contributor
Posts: 87

Re: Using arrays?

Thanks so much! I knew of CATX function but was not sure how will it take care of blanks. But it seems your code took care of that.

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 398 views
  • 1 like
  • 3 in conversation