BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
AlexEt_al_2021
Calcite | Level 5

Hi, 

 

I have compared my solution to the solution shown for lesson 3, practice 5, but I only get a single row of output. 

data is:

  • pg3.storm_maxwindseasqtr
  • pg3.storm_stats

Output line from my attempt:

AlexEt_al_2021_1-1679913976371.png

I have used ChatGPT to assess whether the solution and my solution is doing the same thing, and it seems to be doing the exact same thing, so I don't know where i'm going wrong.

 

I have also tried to use their keywords in the do-loops, but that has not solved

My Solution:


data work.MaxWind; array MWTable[1980:2016,4] _temporary_; if _N_=1 then do S=1980 to 2016; set pg3.storm_maxwindseasqtr; array MWQ[4] MaxWindQ1-MaxWindQ4; do Q=1 to 4; MWTable[S,Q]=MWQ[Q]; end; end; set pg3.storm_stats; Qtr=qtr(StartDate); MaxWindSQ=MWTable[Season,Qtr]; Difference=MaxWindMPH-MaxWindSQ; drop S Q MaxWindQ1-MaxWindQ4; run;




The guided solution is the following:

data work.MaxWind; array MWTable[1980:2016,4] _temporary_; if _N_=1 then do S=1980 to 2016; set pg3.storm_maxwindseasqtr; array MWQ[4] MaxWindQ1-MaxWindQ4; do Q=1 to 4; MWTable[S,Q]=MWQ[Q]; end; end; set pg3.storm_stats; Qtr=qtr(StartDate); MaxWindSQ=MWTable[Season,Qtr]; Difference=MaxWindMPH-MaxWindSQ; drop S Q MaxWindQ1-MaxWindQ4; run;

 

 

What am I doing wrong?

 

Best,

Alex

 

1 ACCEPTED SOLUTION

Accepted Solutions
LinusH
Tourmaline | Level 20

I think you need to add _N_ = 1, otherwise the IF statement will be true for every iteration of the data step.

Data never sleeps

View solution in original post

4 REPLIES 4
LinusH
Tourmaline | Level 20
I fail to see the difference between the two code snippets.
Did you paste the wrong code?
Data never sleeps
AlexEt_al_2021
Calcite | Level 5
Yep... **bleep**, sorry about that.

Here is my solution.

data work.MaxWind;
/* add code to create and load two-dimensional array */
array MWTable[1980:2016,4] _temporary_;

if _N_ then do Yr = 1980 to 2016;
set pg3.storm_maxwindseasqtr;
array MWQ[4] MaxWindQ1-MaxWindQ4;
do Q = 1 to 4;
MWTable[Yr, Q] = MWQ[Q];

end;
end;

set pg3.storm_stats;
Qtr=qtr(StartDate);
/* add code to use two-dimensional array */
MaxWindSQ = MWTable[Season, Qtr];
Difference = MaxWindMPH - MaxWindSQ;
drop Yr Q MaxWindQ1-MaxWindQ4;
run;
LinusH
Tourmaline | Level 20

I think you need to add _N_ = 1, otherwise the IF statement will be true for every iteration of the data step.

Data never sleeps
AlexEt_al_2021
Calcite | Level 5
That's it!! That worked 🙂

Weird how ChatGPT said the two pieces of code achieved the same thing.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
Autotuning Deep Learning Models Using SAS

Follow along as SAS’ Robert Blanchard explains three aspects of autotuning in a deep learning context: globalized search, localized search and an in parallel method using SAS.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 4 replies
  • 1574 views
  • 0 likes
  • 2 in conversation