DATA Step, Macro, Functions and more

SAS program

Reply
Occasional Contributor cm3
Occasional Contributor
Posts: 7

SAS program

Hi, Can someone pls help with the below logic
There are total 25 variables in my dataset and two of them are userformid , Score. I want to populate all 25 values for only first.userformid. For rest all observations populate only Score values.
Thanks
Respected Advisor
Posts: 3,055

Re: SAS program

Sorry, you'll have to show us a (portion of) your data. I don't understand what you want.

 

Also show us the desired output.

 

Don't show us one and not the other.

--
Paige Miller
Occasional Contributor cm3
Occasional Contributor
Posts: 7

Re: SAS program

For ex my data set is like below
Userformid RS min_rs max_rs grade score
E031000. 4. 2. 5. E03. 303
E031000. 2. 2. 5. E03. 303
E031000. 5. 2. 5. E03. 312
E03100S. 1. 1. 4. E03. 309
E03100S. 3. 1. 4. E03. 300
E03100S. 4. 1. 4. E03. 304

I need my output data set as below

Userformid RS min_rs max_rs grade score
E031000. 4 2 5 E03. 303
303
312
E03100S. 1 1 4 E03. 309
300
304

Thank you !
Occasional Contributor cm3
Occasional Contributor
Posts: 7

Re: SAS program

Correction typo mistake below
E031000. 4 2 5 E03. 303
303
312
E03100S. 1 1 4 E03. 309
300
304
Super User
Posts: 13,583

Re: SAS program


@cm3 wrote:
Correction typo mistake below
E031000. 4 2 5 E03. 303
303
312
E03100S. 1 1 4 E03. 309
300
304

Get your text, in a plain text editor like the SAS editor or Notepad. The paste into a code box using the forum's {I} to preserve the format. Otherwise the forum strips a lot of blanks, tabs and such. I am guessing that you intended something like:

E031000. 4 2 5 E03. 303
                    303
                    312
E03100S. 1 1 4 E03. 309
                    300
                    304

which would indeed be a bad structure for an actual data set. If you are wanting a REPORT that is read by people and not data fed into other procedures then say so.

 

 

The reason this would be bad as a data set is that the value of the variable userformid is no longer available for grouping for any purpose on most records. So summarizations and such are likely to be off.

Occasional Contributor cm3
Occasional Contributor
Posts: 7

Re: SAS program

303 312 300 304 are Score values and should be under last column
Userformid RS min_rs max_rs grade as null values
Respected Advisor
Posts: 4,736

Re: SAS program

@cm3

It feels wrong to create such a data structure but here you go.

data want;
  set have;
  by Userformid;
  if not first.Userformid then
    do;
      call missing(Userformid, RS, min_rs, max_rs, grade);
    end;
run;
Ask a Question
Discussion stats
  • 6 replies
  • 114 views
  • 1 like
  • 4 in conversation